Delphi如何获取[主音量]的值,非Wave方式的音量?Delphi如何获取[主音量]的值,非Wave方式的音量?  网上搜索到的大多数是通过wave方式获取到的音量,如何取得主音量有些不明白。

解决方案 »

  1.   

    uses MMSystem;Type
      TDeviceName = (Master, Microphone, WaveOut, Synth);function GetVolume(DN:TDeviceName) : Word; //参数Master为主音量
    var
      hMix: HMIXER;
      mxlc: MIXERLINECONTROLS;
      mxcd: TMIXERCONTROLDETAILS;
      vol: TMIXERCONTROLDETAILS_UNSIGNED;
      mxc: MIXERCONTROL;
      mxl: TMixerLine;
      intRet: Integer;
      nMixerDevs: Integer;
    begin
      Result:=0;
      // Check if Mixer is available
      nMixerDevs := mixerGetNumDevs();
      if (nMixerDevs < 1) then Exit;
      // open the mixer
      intRet := mixerOpen(@hMix, 0, 0, 0, 0);
      if intRet = MMSYSERR_NOERROR then begin
        case DN of
          Master     :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
          Microphone :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
          WaveOut    : mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
          Synth      :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;
        end;
        mxl.cbStruct := SizeOf(mxl);
        // get line info
        intRet := mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
        if intRet = MMSYSERR_NOERROR then begin
          FillChar(mxlc, SizeOf(mxlc),0);
          mxlc.cbStruct := SizeOf(mxlc);
          mxlc.dwLineID := mxl.dwLineID;
          mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
          mxlc.cControls := 1;
          mxlc.cbmxctrl := SizeOf(mxc);
          mxlc.pamxctrl := @mxc;
          intRet := mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
          if intRet = MMSYSERR_NOERROR then begin
            FillChar(mxcd, SizeOf(mxcd),0);
            mxcd.dwControlID := mxc.dwControlID;
            mxcd.cbStruct := SizeOf(mxcd);
            mxcd.cMultipleItems := 0;
            mxcd.cbDetails := SizeOf(Vol);
            mxcd.paDetails := @vol;
            mxcd.cChannels := 1;
            intRet := mixerGetControlDetails(hMix, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
            Result := vol.dwValue ;
          end;
        end;
        mixerClose(hMix);
      end;
    end;
      

  2.   

    我用VC2005写了一个DLL,调用了Vista的EndPointVolume API可以控制、取得Vista的主音量,可以用Delphi调用,楼主需要的话留下邮箱 QQ77266693