Title: Eject Cdrom
Question: mciSendstring('SET CDAUDIO DOOR OPEN
WAIT',nil,0, Handle);
Only open's the first cd drive.
How can i open a outher cd drive??
Answer:
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);
try
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;
result := true;
finally
mp.free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not EjectCD('D') then
ShowMessage('Not A CD Drive');
end;