用butools的soundcontrol控件
trackbar.min:=0;
trackbar.max:=100;
busoundcontrol.wave.balance:=trackbar.position;

解决方案 »

  1.   


    呵呵,不想用控件,可以参考它的源代码:unit BUSoundControl;{*******************************************************}
    {                                                       }
    {   BUPack Component Package                            }
    {   From BuyPin Software - http://www.buypin.com        }
    {                                                       }
    {   Copyright (c) 1998,2000 S閎astien Buysse            }
    {                                                       }
    {*******************************************************}{$ObjExportAll On}interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, BUTypes,
      MMSystem;type
      TBUSoundValue = class(TPersistent)
      private
        FHandle: Integer;
        FOnRefresh: TNotifyEvent;
        FOnUpdate: TNotifyEvent;
        FBalance,FVolume:Integer;
        function GetBalance: TBalance;
        function GetVolume: byte;
        procedure SetBalance(const Value: TBalance);
        procedure SetVolume(const Value: byte);
      protected
        property OnRefresh:TNotifyEvent read FOnRefresh write FOnRefresh;
        property OnUpdate:TNotifyEvent read FOnUpdate write FOnUpdate;
        property Handle:Integer read FHandle write FHandle;
        procedure SetValue(Vol:TVolumeRec);
        function GetValue:TVolumeRec;
      public
        constructor Create;
      published
        property Volume:byte read GetVolume write SetVolume stored false;
        property Balance:TBalance read GetBalance write SetBalance stored false;
      end;  TBUSoundControl = class(TComponent)
      private
        FMidi: TBUSoundValue;
        FCd: TBUSoundValue;
        FWave: TBUSoundValue;
        FLastError: Integer;    procedure OnCdRefresh(Sender: TObject);
        procedure OnWaveRefresh(Sender: TObject);
        procedure OnMidiRefresh(Sender: TObject);
        procedure OnCdUpdate(Sender: TObject);
        procedure OnWaveUpdate(Sender: TObject);
        procedure OnMidiUpdate(Sender: TObject);
      protected
      public
        constructor Create(AOwner: TComponent);override;
        destructor Destroy;override;
        property LastError:Integer read FLastError;
      published
        property Wave:TBUSoundValue read FWave write FWave;
        property Midi:TBUSoundValue read FMidi write FMidi;
        property Cd:TBUSoundValue read FCd write FCd;
      end;implementation{**********************************************************}
    constructor TBUSoundControl.Create(AOwner: TComponent);
    var
      AuxCaps     : TAuxCaps;
      WaveOutCaps : TWaveOutCaps;
      MidiOutCaps : TMidiOutCaps;
      i:Integer;
    begin
      inherited;
      FLastError:=0;
      
      FMidi:=TBUSoundValue.Create;
      FCd:=TBUSoundValue.Create;
      FWave:=TBUSoundValue.Create;  FCd.OnRefresh:=OnCdRefresh;
      FWave.OnRefresh:=OnWaveRefresh;
      FMidi.OnRefresh:=OnMidiRefresh;  FCd.OnUpdate:=OnCdUpdate;
      FWave.OnUpdate:=OnWaveUpdate;
      FMidi.OnUpdate:=OnMidiUpdate;  for i:=0 to auxGetNumDevs-1 do
      begin
        auxGetDevCaps(I, @AuxCaps, SizeOf(AuxCaps));
        if (AuxCaps.dwSupport and AUXCAPS_VOLUME) <> 0 then
        begin
          FCd.Handle:=i;
          break;
        end;
      end;  for i:=0 to waveOutGetNumDevs-1 do
      begin
        waveOutGetDevCaps(I, @WaveOutCaps, SizeOf(WaveOutCaps));
        if (WaveOutCaps.dwSupport and WAVECAPS_VOLUME) <> 0 then
        begin
          FWave.Handle:=i;
          break;
        end;
      end;  for i:=0 to midiOutGetNumDevs-1 do
      begin
        MidiOutGetDevCaps(i, @MidiOutCaps, SizeOf(MidiOutCaps));
        if (MidiOutCaps.dwSupport and MIDICAPS_VOLUME) <> 0 then
        begin
          FMidi.Handle:=I;
          break;
        end;
      end;
    end;
    {**********************************************************}
    destructor TBUSoundControl.Destroy;
    begin
      FMidi.Free;
      FCd.Free;
      FWave.Free;
      inherited;
    end;
    {**********************************************************}
    procedure TBUSoundControl.OnCdRefresh(Sender: TObject);
    var
      Vol:TVolumeRec;
    begin
      with Sender as TBUSoundValue do
      begin
        FLastError:=AuxGetVolume(Handle,@Vol.LongVolume);
        if FLastError=MMSYSERR_NOERROR then SetValue(Vol);
      end;
    end;
    {**********************************************************}
    procedure TBUSoundControl.OnCdUpdate(Sender: TObject);
    var
      Vol:TVolumeRec;
    begin
      with Sender as TBUSoundValue do
      begin
        Vol:=GetValue;
        FLastError:=AuxSetVolume(Handle,Vol.LongVolume);
      end;
    end;
    {**********************************************************}
    procedure TBUSoundControl.OnMidiRefresh(Sender: TObject);
    var
      Vol:TVolumeRec;
    begin
      with Sender as TBUSoundValue do
      begin
        FLastError:=MidiOutGetVolume(Handle,@Vol.LongVolume);
        if FLastError=MMSYSERR_NOERROR then SetValue(Vol);
      end;
    end;
    {**********************************************************}
    procedure TBUSoundControl.OnMidiUpdate(Sender: TObject);
    var
      Vol:TVolumeRec;
    begin
      with Sender as TBUSoundValue do
      begin
        Vol:=GetValue;
        FLastError:=MidiOutSetVolume(Handle,Vol.LongVolume);
      end;
    end;
    {**********************************************************}
    procedure TBUSoundControl.OnWaveRefresh(Sender: TObject);
    var
     Vol:TVolumeRec;
    begin
      with Sender as TBUSoundValue do
      begin
        FLastError:=waveOutGetVolume(Handle,@Vol.LongVolume);
        if FLastError=MMSYSERR_NOERROR then SetValue(Vol);
      end;
    end;
    {**********************************************************}
    procedure TBUSoundControl.OnWaveUpdate(Sender: TObject);
    var
      Vol:TVolumeRec;
    begin
      with Sender as TBUSoundValue do
      begin
        Vol:=GetValue;
        FLastError:=WaveOutSetVolume(Handle,Vol.LongVolume);
      end;
    end;
    {**********************************************************}
    { TBUSoundValue }
    {**********************************************************}
    constructor TBUSoundValue.Create;
    begin
      FHandle:=-1;
    end;
    {**********************************************************}
    function TBUSoundValue.GetBalance: TBalance;
    begin
      if FHandle=-1 then result:=0
      else
      begin
        if Assigned(FOnRefresh) then FOnRefresh(self);
        result:=FBalance;
      end;
    end;
    {**********************************************************}
    function TBUSoundValue.GetValue: TVolumeRec;
    begin
      Result.LeftVolume:=round(((FVolume*FBalance)/100)) shl 9;
      Result.RightVolume:=round(((FVolume*(100-FBalance))/100)) shl 9;
    end;
    {**********************************************************}
    function TBUSoundValue.GetVolume: byte;
    begin
      if FHandle=-1 then result:=0
      else
      begin
        if Assigned(FOnRefresh) then FOnRefresh(self);
        result:=FVolume;
      end;
    end;
    {**********************************************************}
    procedure TBUSoundValue.SetBalance(const Value: TBalance);
    begin
      if FHandle<>-1 then
      begin
        FBalance:=Value;
        if Assigned(FOnUpdate) then FOnUpdate(self);
      end;
    end;
    {**********************************************************}
    procedure TBUSoundValue.SetValue(Vol: TVolumeRec);
    var
     Total:double;
    begin
      FVolume:=(Vol.LeftVolume+Vol.RightVolume) shr 9;
      Total:=(Vol.LeftVolume+Vol.RightVolume) / 100;
      if Total<>0 then
        FBalance:=Round(Vol.LeftVolume/Total);
    end;
    {**********************************************************}
    procedure TBUSoundValue.SetVolume(const Value: byte);
    begin
      if FHandle<>-1 then
      begin
        FVolume:=Value;
        if Assigned(FOnUpdate) then FOnUpdate(self);
      end;
    end;
    {**********************************************************}
    end.
      

  2.   

    http://www.vbapi.com/ref/funcc.html你去这里看看阿~~你的操作系统是什么???是不是win2000???
      

  3.   

    Faint~~~~~失败~~好像2000不支持这个API了~~~我这里没有MSDN~~不知道怎么办了~~Sorry~~