mute the master volume of your soundcard?
uses
MMSystem;
function GetMasterMute(
Mixer: hMixerObj;
var Control: TMixerControl): MMResult;
// Returns True on success
var
Line: TMixerLine;
Controls: TMixerLineControls;
begin
ZeroMemory(@Line, SizeOf(Line));
Line.cbStruct := SizeOf(Line);
Line.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
Result := mixerGetLineInfo(Mixer, @Line,
MIXER_GETLINEINFOF_COMPONENTTYPE);
if Result = MMSYSERR_NOERROR then
begin
ZeroMemory(@Controls, SizeOf(Controls));
Controls.cbStruct := SizeOf(Controls);
Controls.dwLineID := Line.dwLineID;
Controls.cControls := 1;
Controls.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;
Controls.cbmxctrl := SizeOf(Control);
Controls.pamxctrl := @Control;
Result := mixerGetLineControls(Mixer, @Controls,
MIXER_GETLINECONTROLSF_ONEBYTYPE);
end;
end;
procedure SetMasterMuteValue(
Mixer: hMixerObj;
Value: Boolean);
var
MasterMute: TMixerControl;
Details: TMixerControlDetails;
BoolDetails: TMixerControlDetailsBoolean;
Code: MMResult;
begin
Code := GetMasterMute(0, MasterMute);
if Code = MMSYSERR_NOERROR then
begin
with Details do
begin
cbStruct := SizeOf(Details);
dwControlID := MasterMute.dwControlID;
cChannels := 1;
cMultipleItems := 0;
cbDetails := SizeOf(BoolDetails);
paDetails := @BoolDetails;
end;
LongBool(BoolDetails.fValue) := Value;
Code := mixerSetControlDetails(0, @Details,
MIXER_SETCONTROLDETAILSF_VALUE);
end;
if Code <> MMSYSERR_NOERROR then
raise Exception.CreateFmt('SetMasterMuteValue failure, '+
'multimedia system error #%d', [Code]);
end;
// Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
SetMasterMuteValue(0, CheckBox1.Checked); // Mixer device #0 mute on/off
end;
---------------------------------------
mixerSetControlDetails
auxoutsetvolume 是控制CD音量的
waveOutSetVolume 是控制波形的
midiOutSetVolume 是控制FM或者是synthesizer
unit Volume;
interface
uses windows,mmsystem;
type
Tvolume=record
left,right:word; // 取值范围 0--65535
end;
procedure fillstruct(control:PMixerControl;var Cdetails:tMIXERCONTROLDETAILS);
function getpeak(control:PMixerControl;var peak:integer):boolean;
function setvolume(control:Pmixercontrol; volume:Tvolume):boolean;
function getvolume(control:Pmixercontrol; volume:Tvolume):boolean;
var
mcontrols:array of array of array of PMixerControl; //mixer的数组,单声卡可以不用
fmixerhandle:HMIXER; //mixer的句柄
implementation
procedure fillstruct(control:PMixerControl;var Cdetails:tMIXERCONTROLDETAILS);
begin
Cdetails.cbStruct:=sizeof(cdetails);
cdetails.dwControlID:=Control.dwControlID;
cdetails.cbDetails:=sizeof(integer);
cdetails.hwndOwner:=0;
end;
function getpeak(control:PMixerControl;var peak:integer):boolean;
var
details:TMixerControlDetailsSigned;
cdetails:tMIXERCONTROLDETAILS;
begin
Result:=false;
if control.dwControlType<> mixercontrol_controltype_peakmeter then exit;
cdetails.cChannels:=1;
cdetails.paDetails:=@details;
fillstruct(control,cdetails);
result:=mixerGetControlDetails(fmixerhandle,@cdetails,MIXER_GETCONTROLDETAILSF_VALUE)=0;
end;
function setvolume(control:Pmixercontrol; volume:Tvolume):boolean;
var
details:array[0..30] of integer;
cdetails:tMIXERCONTROLDETAILS;
begin
fillstruct(control,cdetails);
cdetails.cChannels:=2;
cdetails.paDetails:=@details;
details[0]:=volume.left;
details[1]:=volume.right;
result:=mixerSetControlDetails(fmixerhandle,@cdetails,MIXER_GETCONTROLDETAILSF_VALUE)=0;
volume.left:=details[0];
volume.right:=details[1];
end;
function getvolume(control:Pmixercontrol; volume:Tvolume):boolean;
var
details:array[0..30] of integer;
cdetails:tMIXERCONTROLDETAILS;
begin
fillstruct(control,cdetails);
cdetails.cChannels:=2;
cdetails.paDetails:=@details;
result:=mixerGetControlDetails(fmixerhandle,@cdetails,MIXER_GETCONTROLDETAILSF_VALUE)=0;
volume.left:=details[0];
volume.right:=details[1];
end;
end.
// 调用方法:
procedure TForm1.Button1Click(Sender: TObject);
var s : Tvolume;
kz : Pmixercontrol;
begin
new(kz); //<------------ 此处一定要分配内存
kz.dwControlID := 0;
s.left := 0;
s.right := 0;
try
setvolume(kz,s);
except
end;
freemem(kz);
end;