From: "Robert Rossmair" Subject: Re: How to programmatically control the volume slider? Date: Wednesday, February 07, 2001 9:03 AM Rob schrieb: > I want to have, on my app that uses a tmediaplayer, a slider that when > moved, controls the sound cards output level. This is what you can do in the > commercial media players, where they have the level slider which controls > the output. This basically controls the volume slider of the app on the > taskbar. Can anyone give a method or example of how to do this? Below an example project which shows how to do this using my Mixer component (freeware w/ source, available from http://home.t-online.de/home/Robert.Rossmair/#TrrMixer). To control the recording volume, replace "Playback" by "Recording". -------------------8<-------------------8<-------------------8<------------------- unit VolDemo1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ComCtrls, rrMixer; type TForm1 = class(TForm) Mixer: TrrMixer; VolumeL: TTrackBar; VolumeR: TTrackBar; procedure VolumeLChange(Sender: TObject); procedure VolumeRChange(Sender: TObject); procedure FormCreate(Sender: TObject); private procedure PlaybackVolumeChange(Sender: TrrMixer; Control: TAudioLineControl); end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.VolumeLChange(Sender: TObject); begin Mixer.Playback.Volume.Position[0] := VolumeL.Max - VolumeL.Position; end; procedure TForm1.VolumeRChange(Sender: TObject); begin Mixer.Playback.Volume.Position[1] := VolumeR.Max - VolumeR.Position; end; procedure TForm1.PlaybackVolumeChange(Sender: TrrMixer; Control: TAudioLineControl); begin VolumeL.Position := VolumeL.Max - Mixer.Playback.Volume.Position[0]; VolumeR.Position := VolumeR.Max - Mixer.Playback.Volume.Position[1]; end; procedure TForm1.FormCreate(Sender: TObject); begin Mixer.DeviceID := 0; VolumeL.Min := Mixer.Playback.Volume.Minimum; VolumeL.Max := Mixer.Playback.Volume.Maximum; VolumeL.Position := VolumeL.Max - Mixer.Playback.Volume.Position[0]; VolumeR.Min := Mixer.Playback.Volume.Minimum; VolumeR.Max := Mixer.Playback.Volume.Maximum; VolumeR.Position := VolumeR.Max - Mixer.Playback.Volume.Position[1]; Mixer.Playback.Volume.OnChange := PlaybackVolumeChange; end; end. -------------------8<-------------------8<-------------------8<------------------- object Form1: TForm1 Left = 192 Top = 120 Width = 217 Height = 277 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object VolumeL: TTrackBar Left = 24 Top = 16 Width = 45 Height = 205 Orientation = trVertical Frequency = 1 Position = 0 SelEnd = 0 SelStart = 0 TabOrder = 0 TickMarks = tmBoth TickStyle = tsManual OnChange = VolumeLChange end object VolumeR: TTrackBar Left = 100 Top = 16 Width = 45 Height = 205 Orientation = trVertical Frequency = 1 Position = 0 SelEnd = 0 SelStart = 0 TabOrder = 1 TickMarks = tmBoth TickStyle = tsManual OnChange = VolumeRChange end object Mixer: TrrMixer DeviceID = 0 Left = 164 Top = 16 end end -------------------8<-------------------8<-------------------8<------------------- Greetings, Robert -- Robert Roßmair