adjusting volume-level using MMSYSTEM

Hi,

I'm writing a CD-player, and I want to control the volume.
I know how to change it, but each time I start the unit at first, my
getvolume procedure returns zero at first, only when I adjust the volume,
it returns the right volume. Is it a way of initialising the aux-device
first?

Does anyone have experience with adjusting the volume using MMSYSTEM.PAS?

Greetings,

Anton Bil

a...@mail.HZeeland.nl

====================================================================
{the unit that changes the volume is like this:}

unit Volume;

interface

uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Buttons,
  StdCtrls, Slider, ExtCtrls, mmsystem, Spin;

const AuxDev:byte=2;

type
  TVolumeDlg = class(TForm)
    OKBtn: TBitBtn;
    Bevel1: TBevel;
    LeftSlider: TSlider;
    RightSlider: TSlider;
    Label1: TLabel;
    Label2: TLabel;
    SpinEdit1: TSpinEdit;
    Label3: TLabel;
    procedure FormActivate(Sender: TObject);
    procedure LeftSliderValueChange(Sender: TObject);
    procedure RightSliderValueChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpinEdit1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure GetVolume;
  end;

var
  VolumeDlg: TVolumeDlg;

implementation

{$R *.DFM}

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

procedure TVolumeDlg.FormActivate(Sender: TObject);
begin
  GetVolume;
  SpinEdit1.MaxValue:=auxGetNumDevs-1;
  SpinEdit1.value:=AuxDev;
end;

procedure TVolumeDlg.LeftSliderValueChange(Sender: TObject);
begin

auxsetvolume(AuxDev,longint(RightSlider.value)*65536+longint(LeftSlider.value));
end;

procedure TVolumeDlg.RightSliderValueChange(Sender: TObject);
begin

auxsetvolume(AuxDev,longint(RightSlider.value)*65536+longint(LeftSlider.value));
end;

procedure TVolumeDlg.FormCreate(Sender: TObject);
var s:string;
begin
  GetVolume;
  str(auxdev:1,s);
  Caption:=Caption+' aux'+s;
end;

procedure TVolumeDlg.SpinEdit1Change(Sender: TObject);
begin
  AuxDev:=SpinEdit1.value;
  FormCreate(Self);
end;

end.