Delphi XE + Win7 x64 编译测试通过
uses
MMSystem;
function EnableMute(const Mute: Boolean): Boolean;
var
hmx: HMIXER;
mxlc: MIXERLINECONTROLS;
mxl: MIXERLINE;
mxc: MIXERCONTROL;
mxcd: tMIXERCONTROLDETAILS;
mxcdMute: MIXERCONTROLDETAILS_BOOLEAN;
begin
Result := False;
if Win32MajorVersion < 6 then
Exit;
if mixerOpen(@hmx, 0, 0, 0, 0) <> MMSYSERR_NOERROR then
Exit;
mxl.cbStruct := SizeOf(mxl);
mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
if mixerGetLineInfo(hmx, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE) = MMSYSERR_NOERROR then
begin
mxlc.cbStruct := SizeOf(MIXERLINECONTROLS);
mxlc.dwLineID := mxl.dwLineID;
mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;
mxlc.cControls := 1;
mxlc.cbmxctrl := SizeOf(MIXERCONTROL);
mxlc.pamxctrl := @mxc;
if mixerGetLineControls(hmx, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE) = MMSYSERR_NOERROR then
begin
mxcdMute.fValue := Integer(Mute);
mxcd.hwndOwner := 0;
mxcd.dwControlID := mxc.dwControlID;
mxcd.cbStruct := SizeOf(mxcd);
mxcd.cbDetails := SizeOf(mxcdMute);
mxcd.paDetails := @mxcdMute;
mxcd.cChannels := 1;
mxcd.cMultipleItems := 0;
Result := mixerSetControlDetails(hmx, @mxcd, MIXER_OBJECTF_HMIXER or MIXER_SETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR;
end;
end;
mixerClose(hmx);
end;