三个TrackBar的属性设置:Max:=255;Frequency:=16;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, mmsystem;
type
TForm1 = class(TForm)
TrackBar1: TTrackBar;
TrackBar2: TTrackBar;
TrackBar3: TTrackBar;
procedure TrackBar1Change(Sender: TObject);
procedure TrackBar2Change(Sender: TObject);
procedure TrackBar3Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
//音量控制
procedure TForm1.TrackBar1Change(Sender: TObject);
var
t,v:Longint;
begin
// if a=0 then
Exit;
t:=TrackBar1.Position;
v:=(t shl 8)or(t shl 24);
waveOutSetVolume(0,v);
end;
//左声道控制
procedure TForm1.TrackBar2Change(Sender: TObject);
var
t,v:Longint;
begin
t:=TrackBar2.Position;
waveOutGetVolume(0,@v);
v:=v and $ffff0000 or (t shl 8);
waveOutSetVolume(0,v);
end;
//右声道控制
procedure TForm1.TrackBar3Change(Sender: TObject);
var
t,v:Longint;
begin
t:=TrackBar3.Position;
waveOutGetVolume(0,@v);
v:=v and $0000ffff or (t shl 24);
waveOutSetVolume(0,v);
end;
//获得当前音量值
procedure TForm1.FormCreate(Sender: TObject);
var
v:longint;
begin
waveOutGetVolume(0,@v);
TrackBar2.Position:=hi(v);
TrackBar3.Position:=hi(v shr 16);
if hi(v)>hi(v shr 16) then
TrackBar1.Position:=hi(v)
else
TrackBar1.Position:=hi(v shr 16);
end;
end.
函数说明:
waveOutSetVolume
第一个参数是波形文件输出设备标识符;
第二个参娄是音量大小。这是一个32位的整数,低16位表示左声道的音量,
高16位表示右声道的音量。
waveOutGetVolume
第一个参数是波形文件输出设备标识符;
第二个参数是一个32位整数的指针。