Parameters
hwo
Handle of an open waveform-audio output device. This parameter can also be a device identifier.
dwVolume
New volume setting. The low-order word contains the left-channel volume setting, and the high-order word contains the right-channel setting. A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.
If a devicedo
es not support both left and right volume control, the low-order word of dwVolume specifies the volume level, and the high-order word is ignored.
对于静音功能,可再用函数时将音量值输入最小.
如果只是想实现静音的话,可直接调用MCISendString函数,命令如下:
Set (设备名或自定义的设备别名) audio all off
left off(左声道静音)
Right off(右声道静音)
设备别名的定义方法也使用MCISendString
Open (声音文件的路径及名称) alias (别名)
关于MCISendString的其他参数设置请参照Win32.hlp;
procedure TForm1.TrackBar1Change(Sender: TObject);
var t,v:longint;
begin
//Set TraackBar1.max:=255;
t:=TrackBar1.Position;
//v's high 16 bits:right Blast;
v's low 16 bits:left blast
v:=(t shl 8)or(t shl 24);
if WaveOutSetVolume(0,v)<>MMSYSERR_NOERROR then
ShowMessage('Fail!');
end;
procedure TForm1.TrackBar2Change(Sender: TObject);
var t,v:longint;
begin
t:=TrackBar2.Position;
WaveOutGetVolume(0,@v);;//Change left blast while keep right
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);//Change right blast while keep left
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 shl 16);
//only use high 8 bits,you can get more obvious effect
// For WaveFormFile,you can use WaveOutGetVolume
// For cd File,you can use auxgetvulume;
TrackBar1.Position:=(TrackBar2.Position+TrackBar3.Position)div 2;
end;