要用到什么函数?
要求一启动程序,就要把系统音量调到中间
要用到API的什么函数?
谢谢:)

解决方案 »

  1.   

    为什么没人回答???
    up,up
      

  2.   

    给焦急等待的人的福音,两个函数一看就明白了:
    (要include "mmsystem.h"和link "winmm.lib")void CVolumeDlg::SetVolume( const DWORD dwVolume )
    {
        MMRESULT                        result;
        HMIXER                          hMixer;
        MIXERLINE                       ml   = {0};
        MIXERLINECONTROLS               mlc  = {0};
        MIXERCONTROL                    mc   = {0};
        MIXERCONTROLDETAILS             mcd  = {0};
        MIXERCONTROLDETAILS_UNSIGNED    mcdu = {0};
        // get a handle to the mixer device
        result = mixerOpen(&hMixer, MIXER_OBJECTF_MIXER, 0, 0, 0);
        if (MMSYSERR_NOERROR == result)
        {
            ml.cbStruct        = sizeof(MIXERLINE);
            ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;        // get the speaker line of the mixer device
            result = mixerGetLineInfo((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE);
            if (MMSYSERR_NOERROR == result)
            {
                mlc.cbStruct      = sizeof(MIXERLINECONTROLS);
                mlc.dwLineID      = ml.dwLineID;
                mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
                mlc.cControls     = 1;
                mlc.pamxctrl      = &mc;
                mlc.cbmxctrl      = sizeof(MIXERCONTROL);            // get the volume controls associated with the speaker line
                result = mixerGetLineControls((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
                if (MMSYSERR_NOERROR == result)
                {
                    mcdu.dwValue    = dwVolume;                mcd.cbStruct    = sizeof(MIXERCONTROLDETAILS);
                    mcd.hwndOwner   = 0;
                    mcd.dwControlID = mc.dwControlID;
                    mcd.paDetails   = &mcdu;
                    mcd.cbDetails   = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
                    mcd.cChannels   = 1;                // set the volume
                    result = mixerSetControlDetails((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE);
                    if (MMSYSERR_NOERROR == result)
                        AfxMessageBox("Volume changed!");
                    else
                        AfxMessageBox("mixerSetControlDetails() failed");
                }
                else
                    AfxMessageBox("mixerGetLineControls() failed");
            }
            else
                AfxMessageBox("mixerGetLineInfo() failed");
        
            mixerClose(hMixer);
        }
        else
            AfxMessageBox("mixerOpen() failed");
    }//====================================================================DWORD CVolumeDlg::GetVolume( void )
    {
        DWORD                           dwVolume = -1;
        MMRESULT                        result;
        HMIXER                          hMixer;
        MIXERLINE                       ml   = {0};
        MIXERLINECONTROLS               mlc  = {0};
        MIXERCONTROL                    mc   = {0};
        MIXERCONTROLDETAILS             mcd  = {0};
        MIXERCONTROLDETAILS_UNSIGNED    mcdu = {0};
        // get a handle to the mixer device
        result = mixerOpen(&hMixer, 0, 0, 0, MIXER_OBJECTF_HMIXER);
        if (MMSYSERR_NOERROR == result)
        {
            ml.cbStruct        = sizeof(MIXERLINE);
            ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;        // get the speaker line of the mixer device
            result = mixerGetLineInfo((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE);
            if (MMSYSERR_NOERROR == result)
            {
                mlc.cbStruct      = sizeof(MIXERLINECONTROLS);
                mlc.dwLineID      = ml.dwLineID;
                mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
                mlc.cControls     = 1;
                mlc.pamxctrl      = &mc;
                mlc.cbmxctrl      = sizeof(MIXERCONTROL);            // get the volume controls associated with the speaker line
                result = mixerGetLineControls((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
                if (MMSYSERR_NOERROR == result)
                {
                    mcd.cbStruct    = sizeof(MIXERCONTROLDETAILS);
                    mcd.hwndOwner   = 0;
                    mcd.dwControlID = mc.dwControlID;
                    mcd.paDetails   = &mcdu;
                    mcd.cbDetails   = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
                    mcd.cChannels   = 1;                // get the volume
                    result = mixerGetControlDetails((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE);
                    if (MMSYSERR_NOERROR == result)
                        dwVolume = mcdu.dwValue;
                    else
                        AfxMessageBox("mixerGetControlDetails() failed");
                }
                else
                    AfxMessageBox("mixerGetLineControls() failed");
            }
            else
                AfxMessageBox("mixerGetLineInfo() failed");
        
            mixerClose(hMixer);
        }
        else
            AfxMessageBox("mixerOpen() failed");    return (dwVolume);
    }