Solved

Eject/Close CD-rom drive in one command

Posted on 2001-09-08
8
1,528 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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
 

Expert Comment

by:sysman3k
ID: 9543180
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Delphi: how to send PJL commands to printer 3 109
error 1.1 400 Bad request idhttp delphi 18 151
Printing problem 2 102
TEMBEDDEDWB how can i change its user agent ? 8 70
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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