下面的例子是采用MFC,在菜单中添加命令项,然后在view类中响应菜单命令来控制系统音量:Project->Setting->Link中添加:Winmm.lib在XXXXXview.cpp中:#include <windows.h>
#include <mmsystem.h>void CMixerOpeninMFXView::OnCustAction()  //菜单命令响应函数
{
// TODO: Add your command handler code here
       MMRESULT rc;              // Return code.
       HMIXER hMixer;            // Mixer handle used in mixer API calls.
       MIXERCONTROL mxc;         // Holds the mixer control data.
       MIXERLINE mxl;            // Holds the mixer line data.
       MIXERLINECONTROLS mxlc;   // Obtains the mixer control.       // Open the mixer. This opens the mixer with a deviceID of 0. If you
       // have a single sound card/mixer, then this will open it. If you have
       // multiple sound cards/mixers, the deviceIDs will be 0, 1, 2, and
       // so on.
       rc = mixerOpen(&hMixer, 0,0,0,0);
       if (MMSYSERR_NOERROR != rc) {
           // Couldn't open the mixer.
       }       // 初始化MIXERLINE结构体
       ZeroMemory(&mxl,sizeof(mxl));
       mxl.cbStruct = sizeof(mxl);       // Specify the line you want to get.  
       mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;       rc = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl,
                              MIXER_GETLINEINFOF_COMPONENTTYPE);
       if (MMSYSERR_NOERROR == rc) {
           // Couldn't get the mixer line.
       }       // 取得控制
       ZeroMemory(&mxlc, sizeof(mxlc));
       mxlc.cbStruct = sizeof(mxlc);
       mxlc.dwLineID = mxl.dwLineID;
       mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
       mxlc.cControls = 1;
       mxlc.cbmxctrl = sizeof(mxc);
       mxlc.pamxctrl = &mxc;
       ZeroMemory(&mxc, sizeof(mxc));
       mxc.cbStruct = sizeof(mxc);
       rc = mixerGetLineControls((HMIXEROBJ)hMixer,&mxlc,
                                  MIXER_GETLINECONTROLSF_ONEBYTYPE);
       if (MMSYSERR_NOERROR != rc) {
           // Couldn't get the control.
       }       // After successfully getting the peakmeter control, the volume range
       // will be specified by mxc.Bounds.lMinimum to mxc.Bounds.lMaximum.       MIXERCONTROLDETAILS mxcd;             // Gets the control values.
       MIXERCONTROLDETAILS_SIGNED volStruct; // Gets the control values.
       long volume;                          // Holds the final volume value.       // 初始化MIXERCONTROLDETAILS structure
       ZeroMemory(&mxcd, sizeof(mxcd));
       mxcd.cbStruct = sizeof(mxcd);
       mxcd.cbDetails = sizeof(volStruct);
       mxcd.dwControlID = mxc.dwControlID;
       mxcd.paDetails = &volStruct;
       mxcd.cChannels = 1;       // 取得当前的音量值
       rc = mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd,
                                    MIXER_GETCONTROLDETAILSF_VALUE);
       if (MMSYSERR_NOERROR == rc) {
           // Couldn't get the current volume.
       }
       volume = volStruct.lValue;       volStruct.lValue = 30000; //设置想要设置的音量值
       rc = mixerSetControlDetails((HMIXEROBJ)hMixer, &mxcd,
   MIXER_SETCONTROLDETAILSF_VALUE);

}如果需要进一步的信息,您可以参看:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mmfunc_0icz.asp等有关信息。
- 微软全球技术中心 VC技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。