Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Eject/Close CD-rom drive in one command

Posted on 2001-09-08
8
Medium Priority
?
1,536 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
Technology Partners: 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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

704 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