AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Welche Nachricht bei Änderung der Lautstärke?
Thema durchsuchen
Ansicht
Themen-Optionen

Welche Nachricht bei Änderung der Lautstärke?

Ein Thema von Garfield · begonnen am 26. Mai 2007 · letzter Beitrag vom 27. Mai 2007
 
Benutzerbild von calculon
calculon

Registriert seit: 16. Sep 2006
256 Beiträge
 
Delphi 7 Personal
 
#2

Re: Welche Nachricht bei Änderung der Lautstärke?

  Alt 27. Mai 2007, 03:04
Aaaaaaaaaaaaaaalso, wenn ich dich richtig verstanden hab', willst du die aktuelle Lautstärkeeinstellung von der Windows (c) Lautstärkeregelung bekommen. http://www.krazz.net/smil/schreiben[1].gif

Dazu folgende Unit benutzen:

Delphi-Quellcode:
{ Frei nach by Serhiy Perevoznyk }
unit Volume;



interface
Uses SysUtils, Windows, MMSystem;



////////////////////////////////////////////////////////////////////////////////
function SetMasterVolume(Value: Cardinal) : boolean;
function GetMasterVolume : Cardinal;
////////////////////////////////////////////////////////////////////////////////
implementation
////////////////////////////////////////////////////////////////////////////////
function InitMixer: HMixer;
var
  Err: MMRESULT;
begin
  Err := mixerOpen(@Result, 0, 0, 0, 0);
  if Err <> MMSYSERR_NOERROR then
    Result := 0;
end;
////////////////////////////////////////////////////////////////////////////////
function GetMasterVolumeControl(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;
////////////////////////////////////////////////////////////////////////////////
function SetMasterVolume(Value: Cardinal) : boolean;
var
  MasterVolume : TMixerControl;
  Details : TMixerControlDetails;
  UnsignedDetails : TMixerControlDetailsUnsigned;
  Code : MMResult;
  Mixer : hMixerObj;
begin
  Mixer := InitMixer;
  Result := false;
  Code := GetMasterVolumeControl(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;
    if(mixerSetControlDetails(Mixer,
                              @Details,
                              MIXER_SETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR)then
      Result := true;
  end;
end;
////////////////////////////////////////////////////////////////////////////////
function GetMasterVolume : Cardinal;
var
  MasterVolume : TMixerControl;
  Details : TMixerControlDetails;
  UnsignedDetails : TMixerControlDetailsUnsigned;
  Code : MMResult;
  Mixer : hMixerObj;
begin
  Mixer := InitMixer;
  Result := 0;
  Code := GetMasterVolumeControl(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;
////////////////////////////////////////////////////////////////////////////////
function GetMasterMute(
  Mixer: hMixerObj;
  var Control: TMixerControl): MMResult;
  // Returns True on success
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_MUTE;
    Controls.cbmxctrl := SizeOf(Control);
    Controls.pamxctrl := @Control;
    Result := mixerGetLineControls(Mixer, @Controls,
      MIXER_GETLINECONTROLSF_ONEBYTYPE);
  end;
end;
////////////////////////////////////////////////////////////////////////////////
function MuteMaster : boolean;
var
  MasterMute: TMixerControl;
  Details: TMixerControlDetails;
  BoolDetails: TMixerControlDetailsBoolean;
  Code: MMResult;
begin
  result := false;
  Code := GetMasterMute(0, MasterMute);
  if(Code = MMSYSERR_NOERROR)then
  begin
    with Details do
    begin
      cbStruct := SizeOf(Details);
      dwControlID := MasterMute.dwControlID;
      cChannels := 1;
      cMultipleItems := 0;
      cbDetails := SizeOf(BoolDetails);
      paDetails := @BoolDetails;
    end;
    mixerGetControlDetails(0, @Details,
      MIXER_GETCONTROLDETAILSF_VALUE);



    LongBool(BoolDetails.fValue) := not LongBool(BoolDetails.fValue);

    if(mixerSetControlDetails(0, @Details,
         MIXER_SETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR)then
      result := true;
  end;
end;
////////////////////////////////////////////////////////////////////////////////
end.
und so an die Info rankommen:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.caption := inttostr(GetMasterVolume);
end;
Die Lautstärke kann hierbei einen Wert zwischen 0 und 65535 annehmen!

Gruß

Calculon
--
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:45 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz