chengjian
asked on
how to eject and close the cdrom
I want to know without tmediaplayer how can i eject and close the cdrom? and if i have two cdrom driver how can i know what cdrom i will eject?
hi, inthe.
problem is still to determine which cd-rom to operate in a multiple-cd-rom machine...
Black Death.
problem is still to determine which cd-rom to operate in a multiple-cd-rom machine...
Black Death.
ASKER
Thanks a lot.
But BlackDeath has told you what the problem is!
Thanks BlackDeath.
But BlackDeath has told you what the problem is!
Thanks BlackDeath.
sorry all i can only do this with tmedia player but i would just make it invisible anyway .
you will have to do something with winapi GETLOGICALDRIVES
it will return device types and the one your after is dtCDAudio
(reject my answer next time i'll read ALL of the question:-)
Barry
you will have to do something with winapi GETLOGICALDRIVES
it will return device types and the one your after is dtCDAudio
(reject my answer next time i'll read ALL of the question:-)
Barry
Hi Chengjian,
Well combine this from the Borland TI with the answer from Inthe, when I saw this Q first didn't have the time to find out how to close the CDROM. So now you can specifically make a call to a CDROM in drive A to Z
Frequently Asked Questions
How can I eject a CD-ROM in code?
Question:
How can I eject a CD-ROM in code?
Answer:
You can use the Windows API function GetDriveType() to test
if the drive is a CD-ROM drive then use the TMediaPlayer
(even if the CD is not an Audio CD) to eject the CD.
Example:
function IsDriveCD(Drive : char) : longbool;
var
DrivePath : string;
begin
DrivePath := Drive + ':\';
result := LongBool(GetDriveType(PCha r(DrivePat h)) and DRIVE_CDROM);
end;
function EjectCD(Drive : char) : bool;
var
mp : TMediaPlayer;
begin
result := false;
Application.ProcessMessage s;
if not IsDriveCD(Drive) then exit;
mp := TMediaPlayer.Create(nil);
mp.Visible := false;
mp.Parent := Application.MainForm;
mp.Shareable := true;
mp.DeviceType := dtCDAudio;
mp.FileName := Drive + ':';
mp.Open;
Application.ProcessMessage s;
mp.Eject;
Application.ProcessMessage s;
mp.Close;
Application.ProcessMessage s;
mp.free;
result := true;
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
if not EjectCD('D') then
ShowMessage('Not A CD Drive');
end;
Hope this helps
:O)
Bruintje.
Well combine this from the Borland TI with the answer from Inthe, when I saw this Q first didn't have the time to find out how to close the CDROM. So now you can specifically make a call to a CDROM in drive A to Z
Frequently Asked Questions
How can I eject a CD-ROM in code?
Question:
How can I eject a CD-ROM in code?
Answer:
You can use the Windows API function GetDriveType() to test
if the drive is a CD-ROM drive then use the TMediaPlayer
(even if the CD is not an Audio CD) to eject the CD.
Example:
function IsDriveCD(Drive : char) : longbool;
var
DrivePath : string;
begin
DrivePath := Drive + ':\';
result := LongBool(GetDriveType(PCha
end;
function EjectCD(Drive : char) : bool;
var
mp : TMediaPlayer;
begin
result := false;
Application.ProcessMessage
if not IsDriveCD(Drive) then exit;
mp := TMediaPlayer.Create(nil);
mp.Visible := false;
mp.Parent := Application.MainForm;
mp.Shareable := true;
mp.DeviceType := dtCDAudio;
mp.FileName := Drive + ':';
mp.Open;
Application.ProcessMessage
mp.Eject;
Application.ProcessMessage
mp.Close;
Application.ProcessMessage
mp.free;
result := true;
end;
procedure TForm1.Button1Click(Sender
begin
if not EjectCD('D') then
ShowMessage('Not A CD Drive');
end;
Hope this helps
:O)
Bruintje.
ASKER
Your program works good but i do not want tmediaplayer
Hmm got to the read question better next time.
ASKER
I can Barely accept the answer for the only points
How can i give both inthe and bruintje points?
How can i give both inthe and bruintje points?
dont worry bout the points mate reject my answer and bruintje
can leave a message as an answer as his way is only way i know how to do what your after.
regards barry
can leave a message as an answer as his way is only way i know how to do what your after.
regards barry
ASKER
inthe: Thanks for your answer. i am sorry.
bruintje: Put it as answer
Thanks all
bruintje: Put it as answer
Thanks all
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
put mmsystem in your uses clause then to open do:
mcisendstring('set cdaudio door open wait',nil,0,handle);
and to close do:
mcisendstring('set cdaudio door closed wait',nil,0,handle);
see more info in mm.hlp under find open / opening simple devices
Regards barry