Fórum Abrir/fechar a porta do CD - Unidade F #147313
19/03/2003
0
Obrigado.
Anonymous
Curtir tópico
+ 0Posts
19/03/2003
Aroldo Zanela
Article #17740: How can I eject a CD-ROM in code?
Question and Answer Database
FAQ2740D.txt How can I eject a CD-ROM in code?
Category :VCL
Platform :All
Product :All 32 bit
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(PChar(DrivePath)) and DRIVE_CDROM);
end;
function EjectCD(Drive : char) : bool;
var
mp : TMediaPlayer;
begin
result := false;
Application.ProcessMessages;
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.ProcessMessages;
mp.Eject;
Application.ProcessMessages;
mp.Close;
Application.ProcessMessages;
mp.free;
result := true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not EjectCD(´D´) then
ShowMessage(´Not A CD Drive´);
end;
7/16/98 4:31:28 PM
Last Modified: 01-SEP-99
Gostei + 0
19/03/2003
Elias Jr
faça o seguinte: logo na uses do form declare MMSystem. Eu não sei com o que vc quer abrir o cdrom, eu vou te passar com o evento onclick dos botões:
procedure TForm1.btabrirClick(Sender: TObject);
begin
mcisendstring(´set cdaudio door open wait´,nil,0,handle);
end;
procedure TForm1.btfecharClick(Sender: TObject);
begin
mcisendstring(´set cdaudio door closed wait´,nil,0,handle);
end; :D
Gostei + 0
19/03/2003
Dor_poa
{ Para abrir }
mciSendString(´Set cdaudio door open wait´, nil, 0, handle);
{ Para fechar }
mciSendString(´Set cdaudio door closed wait´, nil, 0, handle);
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)