Solved

Eject/Close CD-rom drive in one command

Posted on 2001-09-08
8
1,512 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now