1)
uses MMSystem, MPlayer;
type
TCDAction = (_OPEN, _CLOSE);
function OpenCloseCDDrive(Drive: Char; Action: TCDAction): boolean;
{ func to eject or close the cdrom drive. Works on all Audio & }
{ Data CDs, even if there is no CDROM in the drive. }
var
mp : TMediaPlayer;
mciResult: integer;
begin
Result := False;
Application.ProcessMessages;
if not IsDriveCD(Drive) then
begin
MessageDlg(Drive + ':\ is not a CDROM drive.', mtError, [mbOK], 0);
Exit;
end;
Screen.Cursor := crHourGlass;
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;
mciResult := 0;
case Action of
_OPEN : mp.Eject;
_CLOSE: mciResult := mciSendCommand(mp.DeviceID,
MCI_SET, MCI_SET_DOOR_CLOSED, 0);
end;
Application.ProcessMessages;
mp.Close;
Application.ProcessMessages;
case Action of
_OPEN : Result := True;
_CLOSE: Result := mciResult = 0;
end;
finally
mp.Free;
Screen.Cursor := crDefault;
end;
end;
and 2)
uses MMSystem;
procedure OpenCloseCD(TrueForOpenFalseForClose: boolean);
{ Works as well as OpenCloseCDDrive() above, }
{ but you don't have to specify a drive letter. }
{ Thanks to Bence Parhuzamos [parhu...@yahoo.com] for this code. }
var
mci: TMCI_Open_Parms;
begin
FillChar(mci, SizeOf(mci), #0);
mci.lpstrDeviceType := PChar('CDAudio');
mciSendCommand(0, mci_Open, mci_Open_Type, Longint(@mci));
mciSendCommand(mci.wDeviceID, mci_Set, 256*(Byte(not TrueForOpenFalseForClose)+1), 0);
{ MCI_SET_DOOR_OPEN = 256 }
{ MCI_SET_DOOR_CLOSED = 512 }
mciSendCommand(mci.wDeviceID, mci_Close, 0, 0);
end;
--
Thanks,
Jon.
"Kevin Morris" <morr...@spar.ca> wrote in message news:3b5de3f4...@newsgroups.borland.com...
function IsDriveCD(Drive: Char): boolean;
{ func to determine if a given drive is a CDROM drive. }
var
DrivePath: string;
DriveResult: integer;
begin
DrivePath := Drive + ':\';
DriveResult := GetDriveType(PChar(DrivePath));
Result := DriveResult = DRIVE_CDROM;
end;
--
Thanks,
Jon.
"Jon Scott" <jes...@email.com> wrote in message news:3b5dee7f_1@dnews...
sure
uses MMSystem;
..
MciSendString('set cdaudio door open', nil, 0, 0);
..
Regards,
Jack Sudarev.