uses
MMSystem;
const
MasterVolumeControl = 0;
MaxVolume = 65535;
MinVolume = 0;
function _VolumeControl(Mixer: hMixerObj;
var Control: TMixerControl): MMResult;
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_VOLUME;
Controls.cbmxctrl := SizeOf(Control);
Controls.pamxctrl := @Control;
Result := mixerGetLineControls(Mixer,
@Controls,
MIXER_GETLINECONTROLSF_ONEBYTYPE);
end;
end;
procedure SetMasterVolume(Mixer: hMixerObj; Value: Word);
var
MasterVolume : TMixerControl;
Details : TMixerControlDetails;
UnsignedDetails : TMixerControlDetailsUnsigned;
aCode : MMResult;
begin
aCode := _VolumeControl(Mixer, MasterVolume);
if aCode = MMSYSERR_NOERROR
then begin
with Details
do begin
cbStruct := SizeOf(Details);
dwControlID := MasterVolume.dwControlID;
cChannels := 1;
// set all channels
cMultipleItems := 0;
cbDetails := SizeOf(UnsignedDetails);
paDetails := @UnsignedDetails;
end;
UnsignedDetails.dwValue := Value;
aCode := mixerSetControlDetails(Mixer,
@Details,
MIXER_SETCONTROLDETAILSF_VALUE);
end;
if aCode <> MMSYSERR_NOERROR
then
raise Exception.CreateFmt('
SetMasterVolume failure, '+
'
multimedia system error #%d', [aCode]);
end;