Getting the volume and changing of volume

hi,

How do I get the Windows volume, for MasterVolume, Wav volume and Midi volume, and set it up so I can change it with a Slider, I think I will need to make use of Onformcreate and Onsliderchange

So the Code for
Procedure TForm1.onformcreate....
begin
Slider1.Max := ...
Slider1.min := ...
Slider1.Position := ...
end;

and for Sliderchange

Procedure TForm1.onslider1change...
begin
....
end;

Please make it cut and paste code as much as possible, and comment it. So I can follow.
Lot's of points so make it good.
degraefAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BoRiSCommented:
hey degraef

Here is a pas file on how to retrieve the volumes ect...

I got it from one of the best components I've used in a long time it's called cdplayer
by Anton Bil check his page for updates: http://www.HZeeland.nl/~abil/download/download.hml)

unit Volume;

interface

uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Buttons,
  StdCtrls, Slider, ExtCtrls, mmsystem; //add this to uses clause

const AuxDev:byte=2;
      Step : integer = 1000; {volume step}

type
  TChangeVol = (cvUp, cvDown);//to change vol
  TVolType = (vtLeft, vtRight);//type of vol right left etc...
  TVol = array[vtLeft..vtRight]of word;//array for left right
  TVolumeDlg = class(TForm)//form with following comp's on it
    OKBtn: TBitBtn;
    Bevel1: TBevel;
    LeftSlider: TSlider;
    RightSlider: TSlider;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    MainSlider: TSlider;
    Label4: TLabel;
    ComboBox1: TComboBox;
    Panel1: TPanel;
    Help: TBitBtn;
    procedure FormActivate(Sender: TObject);
    procedure RightSliderValueChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure MainSliderValueChange(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure RightSliderMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure RightSliderKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure LeftSliderKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure LeftSliderMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure MainSliderMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure MainSliderKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
    Vol : TVol;
    procedure GetVolume;
    procedure SetVolume;
    procedure initActivate;
    procedure GetVolumes(DevId : word;
                         var VolLeft, VolRight : word);
  end;

var
  VolumeDlg: TVolumeDlg;

implementation

{$R *.DFM}

procedure TVolumeDlg.GetVolume;
var myvolume:longint;
begin
  auxgetvolume(AuxDev,addr(myvolume));
  LeftSlider.value:=myvolume mod 65536;
  RightSlider.value:=myvolume div 65536;
end;

procedure TVolumeDlg.initActivate;
var s:string;
begin
  GetVolumes(auxdev, Vol[vtLeft], Vol[vtRight]);
{  ChangeVol(cvup);
  ChangeVol(cvdown);}
  LeftSlider.value:=vol[vtLeft];
  RightSlider.value:=vol[vtRight];
  ComboBox1.itemindex:=AuxDev;
  str(auxdev:1,s);
  Caption:='Volume aux'+s;
end;


procedure TVolumeDlg.FormActivate(Sender: TObject);
begin
  InitActivate;
end;

procedure TVolumeDlg.SetVolume;
begin
  auxsetvolume(AuxDev,longint(RightSlider.value)*65536+longint(LeftSlider.value));
end;

procedure TVolumeDlg.RightSliderValueChange(Sender: TObject);
begin
 with sender as TSlider do
 begin
  SetVolume;
  if MainSlider.Value<value then
  MainSlider.Value:=value;
  if (MainSlider.Value>LeftSlider.value) and
      (MainSlider.Value>RightSlider.value) then
    if RightSlider.value>LeftSlider.value then
    MainSlider.Value:=RightSlider.value else
     MainSlider.Value:=LeftSlider.value;
 end;
end;

procedure TVolumeDlg.FormCreate(Sender: TObject);
begin
  GetVolume;
end;

procedure TVolumeDlg.MainSliderValueChange(Sender: TObject);
var previous,diff:longint;
    RG:boolean;
begin
  RG:=RightSlider.value>LeftSlider.Value;
  if RG then
  previous:=RightSlider.value else
  previous:=LeftSlider.Value;
  diff:=MainSlider.value-previous;
  RightSlider.value:=RightSlider.value+diff;
  LeftSlider.value:=LeftSlider.value+diff;
end;

procedure TVolumeDlg.ComboBox1Change(Sender: TObject);
begin
  AuxDev:=ComboBox1.itemindex;
  InitActivate;
end;

procedure TVolumeDlg.RightSliderMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  RightSliderValueChange(Self);
end;

procedure TVolumeDlg.RightSliderKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  RightSliderValueChange(Self);
end;

procedure TVolumeDlg.LeftSliderKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  RightSliderValueChange(Self);
end;

procedure TVolumeDlg.LeftSliderMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  RightSliderValueChange(Self);
end;

procedure TVolumeDlg.MainSliderMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  MainSliderValueChange(Self);
end;

procedure TVolumeDlg.MainSliderKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  MainSliderValueChange(Self);
end;

procedure TVolumeDlg.GetVolumes(DevId : word;
                            var VolLeft, VolRight : word);
{volume is returned as a pointer to a DWord with the most
 significant word for the left channel. The channels are
 extracted by treating the DWord as a two element  array and
 accessing the two array elements for the Lt and Rt volumes}
var
  Error : integer;
  TempVol : TVol;
begin
  Error := AuxGetVolume(DevId, @TempVol);
  if Error <> 0 then begin
    Exit;
  end;
  VolLeft := TempVol[vtLeft];
  VolRight := TempVol[vtRight];
end;

end.  

this component is freeware so check it out...

Later
BoRiS
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BoRiSCommented:
here is another one to checkout also very good its form the delphideli

www.delphideli.com

then goto components and then audio its called volumes.zip

excellent

Later
BoRiS
0
ZifNabCommented:
Hi degraef,

For these things I use an excellent freeware component, it can change everything from volume to the balance ....

Look at there delphi pages :

http://web.access.net.au/%7Egchandle/

TVolumeControl: Want your own Win95 volume control in your applications? Then use this. And link it to the
        TBalanceControl component for a complete package. Control the Master, CD, Mic, Auxillary, Midi, Wave, Line-In volume
        levels.
       
        TBalanceControl: Link the balance control to the TVolumeControl to have your own volume and balance control package in
        your applications. Control the Master, CD, Mic, Auxillary, Midi, Wave, Line-In balance levels.

Offcourse, I haven't saw BoRiS components, so if they are better, please NOTIFY me about them.... (so I become also better of this question ;-) )

Regards, ZiF.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

degraefAuthor Commented:
hi,

I downloaded the volumes.zip, haven't looked at it yet, but I suspect it is a slider.
The GrabBag which zifnab suggested I already have.
I should explain I am using the Rxslider from the rxlibrary, because I use a futuristic display I cannot use those W95 looking sliders, with the Rxslider I can choose the layout of the slider with pictures, so I need to use it. I tried linking the rxslider with the volumecontrol from the grabbag but that didn't work, I'll check out the volumes.zip and try the code suggested, will keep you updated
0
degraefAuthor Commented:
No, on both accounts. The volumes.zip requires a trackbar and does not work with rxSlider. Besides it did not have a master volume

And the code, it didn't do anything except with the sliders, they moved together, that is not what I need.

Better ideas please
0
BoRiSCommented:
degraef

The reason for the code was to show you how to get the volume and set the volume

I have edited the volumes.zip and allowed it accept the rxslider and master volume controls etc.

So I'm sure you can do the same, the component comes with the source just add what you need and recompile it...

any problems let me know

Later
BoRiS
0
degraefAuthor Commented:
I havent got a clue how to make a component, let alone change it. The point of me giving 500 points was that someone could give me an example of how to do it. So If you have already made it, then please post the edited pas file here.
0
BoRiSCommented:
I tell you what give me your mail address and i'll mail it you with a description on what is happening...

Then we can grade the answer...

Later
BoRiS
0
degraefAuthor Commented:
E-Mail = bs130956@skynet.be

Thanks, if it works, it will be worth it.
0
BoRiSCommented:
K will send it you

Later
BoRiS
0
ZifNabCommented:
hi all, if you still got problems tomorrow, I'm willing to make a working piece for you. But I guess BoRiS source code will work just fine. Regards, ZiF.
0
degraefAuthor Commented:
At the moment, I am unable to install the new volumes.dcu, because it is compiled under a different version of rxslider, so i'm still waiting, no pressure take your time to make it. :-)
0
BoRiSCommented:
degaef

K I'll check it out, what version of the Rx lib are you using, O I'll change the name to I checkout the the component Zifnab suggested (hmmmm, not bad) but I see they use a volumes unit to.

Well I'll mail you the new Now-Now

Later
BoRiS
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.