Solved

Eject/Close CD-rom drive in one command

Posted on 2001-09-08
8
1,533 Views
Last Modified: 2007-12-19
How can I eject and close cd-rom drive by one button , so if it is closed I eject, if it is opened I close it .
I know that for close :
mcisendmessage('set cdaudio door closed wait',nil,0,handle);
and for Eject is : mcisendmessage('set cdaudio door closed wait',nil,0,handle);
I would know how combine the two commands in one procedure for ejecting or closing cd-rom drive .
0
Comment
Question by:nabildatone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 1

Expert Comment

by:Dennis9
ID: 6467198
listening...
0
 
LVL 1

Expert Comment

by:Dennis9
ID: 6467239
listening...
0
 
LVL 2

Expert Comment

by:DidierD
ID: 6467487
Hi,

I think zifnab is the expert here who knows a lot about it, but i haven't seen him here for a while. The code below comes from him.
 
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

const
  DBT_DEVICEARRIVAL = 32772;
  DBT_DEVICEREMOVECOMPLETE = 32768;

type
  TForm1 = class(TForm)
    procedure WndProc(var Msg: TMessage); override;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WndProc(var Msg: TMessage);
begin
if Msg.Msg = WM_DEVICECHANGE then begin
 case Msg.wParam of
  DBT_DEVICEARRIVAL : begin
    showmessage('CD DOOR OPEN');
   end;
  DBT_DEVICEREMOVECOMPLETE : begin
    showmessage('CD DOOR CLOSE');
   end;
 end;
end
  else inherited WndProc(MSg);
end;

end.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Accepted Solution

by:
DrDelphi earned 50 total points
ID: 6467746
procedure CDOpenClose;
var
  MCIO: TMCI_Open_Parms;
  MCIS: TMCI_Status_Parms;
begin

  MCIO.lpstrDeviceType := PChar(MCI_DEVTYPE_CD_AUDIO);
  if mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or
    MCI_OPEN_SHAREABLE, LongInt(@MCIO)) = 0 then
  begin
    MCIS.dwItem := MCI_STATUS_READY;
    mciSendCommand(MCIO.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM or MCI_WAIT, LongInt(@MCIS));
    if MCIS.dwReturn <> 0 then mciSendCommand(MCIO.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0)
    else
      mciSendCommand(MCIO.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
    mciSendCommand(MCIO.wDeviceID, MCI_CLOSE, MCI_WAIT, 0);
  end;
end;


Good luck!!

0
 

Expert Comment

by:DelFreak
ID: 6467965
Listening...
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6468648
listening...for moment
0
 
LVL 17

Expert Comment

by:geobul
ID: 9295952
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept DrDelphi's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses
Course of the Month3 days, 22 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question