我知道很多人问这个,但我没有看到任何答案,有没有任何lib /通用的方式来GET(不是设置,我不需要它)主音量(当前输出源的音量对于声音,而不是声音),这对于XP / Vista / 7的作品?
如果没有,如何做XP,Vista,七(我会写我的通用包装)
我需要显示一个条(进度条)来显示如何设置当前音量(winform控件)
编辑:
我发现一个有用的链接,我正在testing它,但我不会检查答案,直到我得到的东西是有效的http://www.codeproject.com/KB/audio-video/mixerSetControlDetails.aspx?display=Print
编辑2:
一个重要的事情:以前的方式来分析音量将无法在Windows Vista或更高版本,使用这个库,而不是: http : //www.codeproject.com/KB/vista/CoreAudio.aspx
我不知道是否真的有效,因为我目前还没有vista / seven
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) { } } } } } }