如何 1、更改系统 Playing 主声音音量(注意:是要求主声音,也就是说,更改的是系统右下角的喇叭的音量,而不是单单更改 WAVE 或 CD 或 MIDI 等的音量。),及2、如何将系统音量设为静音,要求设后右下角的喇叭为禁止,3、及如何知道系统目前为静音状态?

解决方案 »

  1.   

    unit WAV_Volume;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes;  function GetWaveVolumeLeft: Word;
      function GetWaveVolumeRight: Word;
      procedure GetWaveVolume(var Left, Right: WORD);
      procedure SetWaveVolume(const Left, Right: WORD);
      function SupportsLAndRVolume: boolean;implementation
    uses mmsystem;{$R-}function _GetWaveVolume: DWORD;
    var
      Woc : TWAVEOUTCAPS;
      Volume : DWORD;
      hwo : UINT;
    begin
      result := 0;  hwo := WAVE_MAPPER;
      if WaveOutGetDevCaps(WAVE_MAPPER, @Woc, sizeof(Woc)) = MMSYSERR_NOERROR then
        if (Woc.dwSupport and WAVECAPS_VOLUME) = WAVECAPS_VOLUME then
        begin
          if WaveOutGetVolume(hwo, @Volume) = MMSYSERR_NOERROR then
            Result := Volume;
        end;
    end;procedure _SetWaveVolume(const AVolume: DWORD);
    var
      Woc : TWAVEOUTCAPS;
      hwo : UINT;
    begin
      hwo := WAVE_MAPPER;  if WaveOutGetDevCaps(WAVE_MAPPER, @Woc, sizeof(Woc)) = MMSYSERR_NOERROR then
        if (Woc.dwSupport and WAVECAPS_VOLUME) = WAVECAPS_VOLUME then
          WaveOutSetVolume(hwo, AVolume);
    end;function GetWaveVolumeLeft: Word;
    var
      d : DWORD;
    begin
      d := _GetWaveVolume;
      result := LOWORD(d);
    end;function GetWaveVolumeRight: Word;
    var
      d : DWORD;
    begin
      d := _GetWaveVolume;
      result := HIWORD(d);
    end;procedure GetWaveVolume(var Left, Right: WORD);
    var
      d : DWORD;
    begin
      d := _GetWaveVolume;
      Left  := LOWORD(d);
      Right := HIWORD(d);
    end;
    procedure SetWaveVolume(const Left, Right: WORD);
    var
      d : DWORD;
    begin
      d := MAKELONG(Left, Right);
      _SetWaveVolume( d );
    end;function SupportsLAndRVolume: boolean;
    var
      Woc : TWAVEOUTCAPS;
      Volume : DWORD;
      hwo : UINT;
    begin
      result := false;  hwo := WAVE_MAPPER;
      if WaveOutGetDevCaps(WAVE_MAPPER, @Woc, sizeof(Woc)) = MMSYSERR_NOERROR then
        result := (Woc.dwSupport and WAVECAPS_LRVOLUME) = WAVECAPS_LRVOLUME;
    end;end.
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ComCtrls, StdCtrls,MMSystem, Buttons;type
      TForm1 = class(TForm)
        BitBtn1: TBitBtn;
        BitBtn2: TBitBtn;
        TrackBar1: TTrackBar;
        procedure BitBtn1Click(Sender: TObject);
        procedure BitBtn2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.BitBtn1Click(Sender: TObject);
      var
      ls:integer;
    begin
      ls:=Self.TrackBar1.Position*255;
      WaveOutSetVolume(ls,0);
    end;procedure TForm1.BitBtn2Click(Sender: TObject);
      var
      ls:integer;
    begin
      ls:=Self.TrackBar1.Position*255;
      WaveOutSetVolume(ls,65535);
    end;end.
      

  3.   

    http://hubdog.csdn.net/Recommend/rcAudioMixer.htm我以前也做過, 比較上面的簡單好多, 實現你要的兩個功能!
    在我的程序拉, 能同時見到變化, 但現在在外地, 沒法拷代碼給你!