Autor Beitrag
Mindforce
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Mi 02.08.06 10:49 
Hi,

ich wollte mal fragen, ob ich ein Code von euch haben darf,mit dem ich die Lautstärke in Windows ändern kann.
Ja ich hab auch schon im Forum gesucht, aber nichts richtiges, das dazu passt. :roll:
Ich bracuhe einen, wo ich ein Integer Wert in ein Edit eingeben kann, und mit nem Button abschicken kann.

Gruss,

M!ndbyte

_________________
Our force; in mind.
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Mi 02.08.06 11:50 
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Mi 02.08.06 11:57 
Hi,

kann man die functions auch mit einem Button ausführen???
Denn wenn ich eine Zahl eingebe in nem Edit, so soll er die IntegerZahl auch dementsprechend der Lautstärke anpassen...

Gruss,

M!ndbyte

_________________
Our force; in mind.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 02.08.06 12:16 
Natürlich kannst du die Funktionen auch per Buttonklick ausführen. Setz einfach ins OnClick den entsprechenden Aufruf der Funktion. Den String aus dem Editfeld kannst du mit IntToStr in einen Intgerwert konvertieren, der dann als Parameter für die Funktion dienen kann.

_________________
We are, we were and will not be.
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Mi 02.08.06 21:23 
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:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
nit 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


Wie wurde der Code denn deklariert??? LOQ

Gruss,

M!ndbyte

_________________
Our force; in mind.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Mi 02.08.06 22:30 
Ööhm.. Eigentlich... garnicht. Code wird nicht deklariert... Variablen werden deklariert. Das geschieht im Code. In so fern verstehe ich die Frage nicht.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Do 03.08.06 09:22 
Du fügst den Code in dein Projekt ein und nutzt die Funktionen
ausblenden Delphi-Quelltext
1:
2:
function SetMasterVolume(Value: Cardinal) : boolean; //Setzt die Lautstärke
function GetMasterVolume : Cardinal; //ermittelt aktuelle Lautstärke


Nehmen wir mal an du hast ein Edit mit dem Namen edit1 und eine Button Button1 dann schreibst du in das OnClick-Ereignis des Buttons :
ausblenden Delphi-Quelltext
1:
SetMasterVolume(StrToInt(edit1.text);					


Nehemn wir weiterhin an du hast noch 2 Buttons btnLauter und btnLeiser, dann belegst du die OnClickEvents der Buttons so :

OnClickEvent von btnLeiser :
ausblenden Delphi-Quelltext
1:
SetMasterVolume(GetMasterVolume-1);					


OnClickEvent von btnLauter :
ausblenden Delphi-Quelltext
1:
SetMasterVolume(GetMasterVolume+1);					


Hoffe, du hast das jetzt verstanden :wink: