Thema: Delphi Haupt Lautstärke Regeln

Einzelnen Beitrag anzeigen

Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#7

Re: Haupt Lautstärke Regeln

  Alt 24. Feb 2007, 16:15
[code=delphi]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;
Code : MMResult;
begin
Code := _VolumeControl(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;

function GetMasterVolume(Mixer: hMixerObj): Word;
var
MasterVolume : TMixerControl;
Details : TMixerControlDetails;
UnsignedDetails : TMixerControlDetailsUnsigned;
Code : MMResult;
begin
Result := 0;

Code := _VolumeControl(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;
Code := mixerGetControlDetails(Mixer,
@Details,
MIXER_GETCONTROLDETAILSF_VALUE);

Result := UnsignedDetails.dwValue;
end;
if Code <> MMSYSERR_NOERROR then
raise Exception.CreateFmt('GetMasterVolume failure, '+
'multimedia system error #%d',
Code:
);
end;

procedure TFormX.Foo...
begin
  // Set
  SetMasterVolume(MasterVolumeControl, 0815); // MaxVolume => 65535

  // Get
  Caption := IntToStr( GetMasterVolume(MasterVolumeControl) );
end;
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat