Autor Beitrag
Tarry
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 213
Erhaltene Danke: 1



BeitragVerfasst: Di 25.11.08 00:51 
Hi,
ich suche fuer meinen Wecker (in der Freeware Sparte) nach einer Moeglichkeit die Master Lautstaerke in Vista auszulesen und zu aendern.

Bei meiner suche bin ich immer wieder auf diesen Code gestossen:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
{ Frei nach by Serhiy Perevoznyk }
unit Volume;

interface
Uses SysUtils, Windows, MMSystem;

////////////////////////////////////////////////////////////////////////////////
function SetMasterVolume(Value: Cardinal) : boolean;
function GetMasterVolume : Cardinal;
procedure SetDeviceVolume(var volLe, volRi: Word);
procedure SetWaveVolume(var volLe, volRi: Word);
////////////////////////////////////////////////////////////////////////////////
implementation
////////////////////////////////////////////////////////////////////////////////
function InitMixer: HMixer;
var 
  Err: MMRESULT; 
begin 
  Err := mixerOpen(@Result, 0000);
  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
////////////////////////////////////////////////////////////////////////////////
//aus SoundControl.pas
////////////////////////////////////////////////////////////////////////////////
procedure SetWaveVolume(var volLe, volRi: Word);
  var
    hWO: HWAVEOUT;
    waveF: TWAVEFORMATEX;
    vol: DWORD;
  begin
    FillChar(waveF, SizeOf(waveF), 0);
    waveOutOpen(@hWO, WAVE_MAPPER, @waveF, 000);
    vol := volLe + volRi shl 16;
    waveOutSetVolume(hWO, vol);
    waveOutClose(hWO);
  end;

procedure SetDeviceVolume(var volLe, volRi: Word);
  var vol: DWORD;
    huhu: Boolean;
  begin
    vol := volLe + volRi shl 16;
    huhu:=SetMasterVolume(vol);
  end;

end.


Der aber unter Vista nichzu funktionieren scheint :(

gruss
Thomas

PS; Ich moechte, w.enn moeglich keine Komponente benutzen


Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Mo 24.11.2008 um 23:55

_________________
"Es gibt zwei Dinge, die unendlich sind. Das Universum und die menschliche Dummheit. Beim Universum bin ich mir noch nicht ganz sicher." -Albert Einstein
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 25.11.08 03:25 
Das wurde bereits hier gefragt, ich habe allerdings nicht die Zeit gehabt mich näher damit zu beschäftigen wie welche Interfaces benutzt werden müssen, vielleicht helfen dir ja die Links, die ich dort in der ersten Antwort gepostet hatte:
www.delphiforum.de/viewtopic.php?p=533620
Tarry Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 213
Erhaltene Danke: 1



BeitragVerfasst: Di 25.11.08 05:07 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Das wurde bereits hier gefragt, ich habe allerdings nicht die Zeit gehabt mich näher damit zu beschäftigen wie welche Interfaces benutzt werden müssen, vielleicht helfen dir ja die Links, die ich dort in der ersten Antwort gepostet hatte:
www.delphiforum.de/viewtopic.php?p=533620


Danke fuer deine Antwort.
Aber leider muss ich gestehen, dass ich wie die anderen in dem Post noch ueberhaupt keine Erfahrung mit Interface habe.
Ich hatte auf eine einfache Unit oder so gehofft, mit der ich dann einfach die Volume in % einstellen koennte...
Wenn es so kompliziert zu sien scheint, werde ich es wahrscheinlich erstmal auf Eis legen, es ist nur ein Nebenaspekt meines Programmes und ich hab einfach nicht die Zeit ein eigenes Programm dafuer zu schreiben.... :(

Aber nochmals danke fuer deine Muehe !
Gruss
Tarry

_________________
"Es gibt zwei Dinge, die unendlich sind. Das Universum und die menschliche Dummheit. Beim Universum bin ich mir noch nicht ganz sicher." -Albert Einstein