So:
[code=delphi]// GetMasterVolumeCtrl - Verwendung intern
//
function GetMasterVolumeCtrl(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;
// SetMasterVolume
// Verwendung: Setzen eines Wertes für das MasterVolume des Mixers
procedure SetMasterVolume(Value: Word);
var
MasterVolume: TMixerControl;
Details: TMixerControlDetails;
UnsignedDetails: TMixerControlDetailsUnsigned;
Mixer: hMixerObj;
Code: MMResult;
begin
MixerOpen(@Mixer, 0, 0, 0, 0);
Code := GetMasterVolumeCtrl(Mixer, MasterVolume);
if Code = 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;
Code := mixerSetControlDetails(Mixer,
@Details,
MIXER_SETCONTROLDETAILSF_VALUE);
end;
if Code <> MMSYSERR_NOERROR then
raise
Exception.CreateFmt('SetMasterVolume failure, ' +
'multimedia system error #%d',
Code:
);
end;
// GetMasterVolume
// Verwendung: akt. Wert des MasterVolumes des Mixers auslesen
function GetMasterVolume: Cardinal;
var
MasterVolume: TMixerControl;
Details: TMixerControlDetails;
UnsignedDetails: TMixerControlDetailsUnsigned;
Code: MMResult;
Mixer: hMixerObj;
mmError: Cardinal;
begin
mmError := MixerOpen(@Mixer, 0, 0, 0, 0);
if mmError <> MMSYSERR_NOERROR then
begin
raise
Exception.CreateFmt('GetMasterVolume failure, ' +
'multimedia system error #%d', [mmError]);
end else
begin
Result := 0;
Code := GetMasterVolumeCtrl(Mixer, MasterVolume);
if (Code = 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;
if (mixerGetControlDetails(Mixer,
@Details,
MIXER_GETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR) then
result := UnsignedDetails.dwValue;
end;
end;
end;
Der selbe Code nur einwenig anders um das Volume zu setzen.
Ein fertiges Beispiel im Anhang.