gpt4 book ai didi

c# - 在Windows XP/Vista/Seven中获得GET Master音量(通常通过键盘滚轮增加音量)

转载 作者:行者123 更新时间:2023-12-03 01:04:18 33 4
gpt4 key购买 nike

我知道很多人问过这个问题,但是我没有读任何答案,是否有任何lib /通用方法来获取(未设置,我不需要)主卷(当前输出源的卷)声音,而不是声音)对xp / vista / seven都适用?

如果没有,如何针对xp,vista,7(我将编写通用包装器)进行处理

我需要显示一个进度条以显示如何设置当前音量(winform控件)

编辑:

我找到了一个有用的链接,我正在测试它,但是我不会检查答案,直到我得到有用的东西为止
http://www.codeproject.com/KB/audio-video/mixerSetControlDetails.aspx?display=Print

编辑2:

重要的是:以前的卷分析方法在Windows Vista或更高版本上不起作用,请改用以下lib:
http://www.codeproject.com/KB/vista/CoreAudio.aspx

我不知道是否真的行得通,因为我目前没有远景/七

最佳答案

mixerGetNumDevs和相关的API有帮助吗? (您必须遍历所有带有mixerGetLineControls等的设备,并查看哪个MIXERCONTROL会说出“Volume”作为名称;还有一种方法可以检查标志。这就是您要查找的标志。)

编辑:

这是我的一些旧代码的片段;我不认为它可以编译,也不是很好的代码(我只需要完成工作即可),但是它应该会有所帮助:

MMRESULT mmResult = mixerOpen(&hMixer, 0, (DWORD_PTR)hWnd, NULL, CALLBACK_WINDOW | MIXER_OBJECTF_MIXER);
if (MMSYSERR_NOERROR == mmResult)
{
MIXERLINE mxl;
mxl.cbStruct = sizeof(MIXERLINE);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
MMRESULT mmResult = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl, MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE);
if (mmResult == MMSYSERR_NOERROR)
{
MIXERLINECONTROLS controls;
memzero(&controls, sizeof(controls));
controls.cbStruct = sizeof(controls);
controls.cControls = 1;
controls.dwLineID = mxl.dwLineID;
controls.cbmxctrl = sizeof(MIXERCONTROL); //one element only!!
MIXERCONTROL controlsArray[2]; //First element: volume, second element: mixer
memzero(&controlsArray, sizeof(controlsArray));
for (int i = 0; i < sizeof(controlsArray) / sizeof(*controlsArray); i++) { controlsArray[0].cbStruct = sizeof(controlsArray[0]); }

controls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
controls.pamxctrl = &controlsArray[0]; //NOTE: this is ZERO
mmResult = mixerGetLineControls((HMIXEROBJ)hMixer, &controls, MIXER_GETLINECONTROLSF_ONEBYTYPE | MIXER_OBJECTF_HMIXER);
if (mmResult == MMSYSERR_NOERROR)
{
controls.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
controls.pamxctrl = &controlsArray[1]; //NOTE: this is ONE
mmResult = mixerGetLineControls((HMIXEROBJ)hMixer, &controls, MIXER_GETLINECONTROLSF_ONEBYTYPE | MIXER_OBJECTF_HMIXER);
if (mmResult == MMSYSERR_NOERROR)
{
bool isVolume = controls[0].dwControlID == (DWORD)lParam;
bool isMute = controls[1].dwControlID == (DWORD)lParam;
if (isVolume | isMute)
{
MIXERCONTROLDETAILS details;
memzero(&details, sizeof(details));
details.cbStruct = sizeof(details);
details.cChannels = 1;
details.dwControlID = (DWORD)lParam;
MIXERCONTROLDETAILS_UNSIGNED controlDetail;
memzero(&controlDetail, sizeof(controlDetail));
details.paDetails = &controlDetail;
details.cbDetails = sizeof(controlDetail);
MMRESULT mmResult = mixerGetControlDetails((HMIXEROBJ)hMixer, &details, MIXER_GETCONTROLDETAILSF_VALUE | MIXER_OBJECTF_HMIXER);
if (mmResult == MMSYSERR_NOERROR)
{
}
}
}
}
}
}

关于c# - 在Windows XP/Vista/Seven中获得GET Master音量(通常通过键盘滚轮增加音量),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4629816/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com