Board index » delphi » CD-ROM Open/Close

CD-ROM Open/Close

Hi,

how can i open and close my CD_ROM ?

I tried lots of samples, but that dosen't work. (mmsystem)

 

Re:CD-ROM Open/Close


The following examples work, but only if no other program (like
cdplayer.exe) is currently using the cd player.

uses
  MMSystem;

procedure OpenCD;
begin
  mciSendString('set cdaudio door open wait', nil, 0, Application.Handle);
end;

procedure CloseCD;
begin
  mciSendString('set cdaudio door closed wait', nil, 0, Application.Handle);
end;

"hazard-fish - Simon Maier" <hazard-f...@world4you.com> schreef in bericht
news:3a5daf68.9703657@news.cis.dfn.de...

Quote

> Hi,

> how can i open and close my CD_ROM ?

> I tried lots of samples, but that dosen't work. (mmsystem)

Re:CD-ROM Open/Close


On Thu, 11 Jan 2001 17:45:19 +0100, "M.H. Avegaart"

Quote
<avegaartNOS...@mccomm.nl> wrote:
>The following examples work, but only if no other program (like
>cdplayer.exe) is currently using the cd player.

>uses
>  MMSystem;

>procedure OpenCD;
>begin
>  mciSendString('set cdaudio door open wait', nil, 0, Application.Handle);
>end;

>procedure CloseCD;
>begin
>  mciSendString('set cdaudio door closed wait', nil, 0, Application.Handle);
>end;

Very cool, is there a way to specify which CD ROM drive you want if
there's more than one?

Stephen Posey
slpo...@concentric.net

Re:CD-ROM Open/Close


Stephen Posey schrieb:

Quote
> Very cool, is there a way to specify which CD ROM drive you want if
> there's more than one?

function SetCDTrayOpen( Drive: char; Open: boolean ): boolean;
var
  Cmd: string;
begin
  Cmd := 'open '+Drive+':'+' type cdaudio alias CDDrive';
  if (mciSendString(PChar(Cmd),nil,0,0) <> 0) then
    Result := false
  else begin
    if (Open) then
      Cmd := 'set CDDrive door open'
    else
      Cmd := 'set CDDrive door closed';
    mciSendString(PChar(Cmd),nil,0,0);
    mciSendString('close CDDrive',nil,0,0);
    Result := true;
  end;
end;

-Michael

Re:CD-ROM Open/Close


On 12 Jan 2001 02:50:32 GMT, slpo...@concentric.net (Stephen Posey)
wrote:

Quote
>On Thu, 11 Jan 2001 17:45:19 +0100, "M.H. Avegaart"
><avegaartNOS...@mccomm.nl> wrote:

>>The following examples work, but only if no other program (like
>>cdplayer.exe) is currently using the cd player.

[..]

Quote
>Very cool, is there a way to specify which CD ROM drive you want if
>there's more than one?

uses
  Windows, SysUtils, MMSystem;

function OpenCD(Drive : Char) : MciError;
Var
  OpenParm: TMCI_Open_Parms;
  Flags : DWord;
  S : String;
  DeviceID : Word;
begin
  S:=Drive+':';
  Flags:=mci_Open_Type or mci_Open_Element;
  With OpenParm do begin
    dwCallback := 0;
    lpstrDeviceType := 'CDAudio';
    lpstrElementName := PChar(S);
  end;
  Result := mciSendCommand(0, mci_Open, Flags, Longint(@OpenParm));
  IF Result<>0 Then exit;
  DeviceID:=OpenParm.wDeviceID;
  try
    Result:=mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
    IF Result<>0 Then exit;
  finally
    mciSendCommand(DeviceID, mci_Close, Flags, Longint(@OpenParm));
  end;
end;

If you replace MCI_SET_DOOR_OPEN with MCI_SET_DOOR_CLOSED you can make
this function close the drive.

--

Jan Peter Stotz

jpst...@gmx.de
      _  ____   ____
     | ||  _ \ / ___|
  _  | || |_) |\___ \
 | |_| ||  __/  ___) |
  \___/ |_|    |____/

Other Threads