Windows XP:
function SetMasterVolume(VolToSet: word; out VolSet: word): MMResult;
var
MixerHandle: HMixer;
Volume: TMixerControlDetails_Unsigned;
MixerLine: TMixerLine;
MixerLineControls: TMixerLineControls;
VolumeCtrl: TMixerControl;
MixerControlDetails: TMixerControlDetails;
begin
// Get mixer handle
Result := mixerOpen(@MixerHandle, 0, 0, 0, 0);
if Result <> MMSYSERR_NOERROR then Exit;
try
// Get master volume line
FillChar(MixerLine, SizeOf(TMixerLine), 0);
MixerLine.cbStruct := SizeOf(TMixerLine);
MixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
Result := mixerGetLineInfo(MixerHandle, @MixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE);
if Result <> MMSYSERR_NOERROR then Exit;
// Get the volume control of the master volume line
FillChar(VolumeCtrl, SizeOf(TMixerControl), 0);
MixerLineControls.cbStruct := SizeOf(TMixerLineControls);
MixerLineControls.dwLineID := MixerLine.dwLineID;
MixerLineControls.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
MixerLineControls.cControls := 1;
MixerLineControls.cbmxctrl := SizeOf(TMixerControl);
MixerLineControls.pamxctrl := @VolumeCtrl;
Result := mixerGetLineControls(MixerHandle,@MixerLineControls,MIXER_GETLINECONTROLSF_ONEBYTYPE);
if Result <> MMSYSERR_NOERROR then Exit;
// Set details (volume) for the volume control of the master volume line
FillChar(MixerControlDetails, SizeOf(TMixerControlDetails), 0);
MixerControlDetails.cbStruct := SizeOf(TMixerControlDetails);
MixerControlDetails.dwControlID := VolumeCtrl.dwControlID;
MixerControlDetails.cChannels := 1;
MixerControlDetails.cMultipleItems := 0;
MixerControlDetails.cbDetails := SizeOf(TMixerControlDetails_Unsigned);
MixerControlDetails.paDetails := @Volume;
Volume.dwValue := VolToSet;
Result := mixerSetControlDetails(MixerHandle, @MixerControlDetails,MIXER_SETCONTROLDETAILSF_VALUE);
finally
mixerClose(MixerHandle);
end;
end;
И вызов:
var y:word;
begin
SetMasterVolume(2000,y);
end;