Попробуй это код для громкости
Код:
var
VolumeBar: TProgressBar;
cmdMinVolume: TSpeedButton;
cmdMaxVolume: TSpeedButton;
procedure TMainForm.FormCreate(Sender: TObject);
var
i: integer;
MixLine: TMixerLine;
MixLineCtrl: TMixerLineControls;
MixCtrl: TMixerControl;
begin
inherited;
MixerOpen(@hmix, 0, Handle, 0, MIXER_OBJECTF_MIXER or CALLBACK_WINDOW);
MixerGetDevCaps(0, @mixcaps, SizeOf(MixCaps));
for I := 0 to MixCaps.cDestinations - 1 do
begin
Mixline.dwDestination := I;
Mixline.cbStruct := SizeOf(Mixline);
MixerGetLineInfo(hmix, @mixline, MIXER_GETLINEINFOF_DESTINATION);
if Mixline.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS then
break;
end;
if Mixline.dwComponentType <> MIXERLINE_COMPONENTTYPE_DST_SPEAKERS then
begin
ShowMessage('Микшер не найден !');
svEnable := False;
Exit;
end
else
svEnable := True;
MixLineCtrl.cbStruct := SizeOf(MixLineCtrl);
MixLineCtrl.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
MixLineCtrl.dwLineID := MixLine.dwLineID;
MixLineCtrl.cControls := 2;
MixLineCtrl.cbmxctrl := Sizeof(MixCtrl);
MixCtrl.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
MixLineCtrl.pamxctrl := @MixCtrl;
MixerGetLineControls(hmix, @mixlinectrl, MIXER_GETLINECONTROLSF_ONEBYTYPE);
VolumeID := MixCtrl.dwControlID;
VolMin := MixCtrl.Bounds.dwMinimum;
VolMax := MixCtrl.Bounds.dwMaximum;
Details.cbStruct := Sizeof(Details);
Details.dwControlID := VolumeID;
Details.cChannels := 1;
Details.cMultipleItems := 0;
Details.cbDetails := SizeOf(Valdets);
Details.paDetails := @valdets;
MixerGetControlDetails(hmix, @details, MIXER_GETCONTROLDETAILSF_VALUE);
CurVolume := Valdets.dwValue;
VolumeBar.Min := VolMin;
VolumeBar.Max := VolMax;
VolumeBar.Position := CurVolume;
procedure TMainForm.VolumeBarMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
begin
if not svEnable then exit;
X := Round(X / VolumeBar.Width * (VolumeBar.Max - VolumeBar.Min) + VolumeBar.Min);
VolumeBar.Position := X;
Details.cbStruct := Sizeof(Details);
Details.dwControlID := VolumeID;
Details.cChannels := 1;
Details.cMultipleItems := 0;
Details.cbDetails := Sizeof(Valdets);
Details.paDetails := @Valdets;
if X > 4000 then
Valdets.dwValue := VolumeBar.Position
else
Valdets.dwValue := 0;
MixerSetControlDetails(hmix, @details, MIXER_SETCONTROLDETAILSF_VALUE);
end;
procedure TMainForm.cmdMinVolumeClick(Sender: TObject);
begin
if not svEnable then Exit;
VolumeBar.Position := VolumeBar.Position - (VolumeBar.Max - VolumeBar.Min) div 50;
if VolumeBar.Position < VolumeBar.Min then
VolumeBar.Position := VolumeBar.Min;
Details.cbStruct := SizeOf(Details);
Details.dwControlID := VolumeID;
details.cChannels := 1;
Details.cMultipleItems := 0;
Details.cbDetails := SizeOf(Valdets);
Details.paDetails := @Valdets;
if VolumeBar.Position > 4000 then
valdets.dwValue := VolumeBar.Position
else
valdets.dwValue := 0;
MixerSetControlDetails(hmix, @details, MIXER_SETCONTROLDETAILSF_VALUE);
end;
procedure TMainForm.cmdMaxVolumeClick(Sender: TObject);
begin
if not svEnable then Exit;
VolumeBar.Position := VolumeBar.Position + (VolumeBar.Max - VolumeBar.Min) div 50;
if VolumeBar.Position > VolumeBar.Max then
VolumeBar.Position := VolumeBar.Max;
Details.cbStruct := SizeOf(Details);
Details.dwControlID := VolumeID;
Details.cChannels := 1;
Details.cMultipleItems := 0;
Details.cbDetails := SizeOf(Valdets);
Details.paDetails := @Valdets;
if VolumeBar.Position > 4000 then
Valdets.dwValue := VolumeBar.Position
else
Valdets.dwValue := 0;
MixerSetControlDetails(hmix, @details, MIXER_SETCONTROLDETAILSF_VALUE);
end;
end;