//Open
begin
mcisendstring('set cdaudio door open wait',nil,o,handle);
end
//close
begin
mcisendstring('set cdaudio door closed wait',nil,o,handle);
end
procedure TCDEvents.WMDeviceChange(var Msg : TWMDeviceChange);
var lpdb : PDEV_BROADCAST_HDR;
lpdbv : PDEV_BROADCAST_VOLUME;
begin
(* received a wm_devicechange message *)
lpdb := PDEV_BROADCAST_HDR(Msg.dwData);
(* look at the event send together with the wm_devicechange message *)
case Msg.Event of
DBT_DEVICEARRIVAL : begin
if lpdb^.dbch_devicetype = DBT_DEVTYP_VOLUME then begin
lpdbv := PDEV_BROADCAST_VOLUME(Msg.dwData);
if (lpdbv^.dbcv_flags and DBTF_MEDIA) = 1 then
Application.MessageBox (' CDROM closed.',
'CDROM Information.',
MB_OK);
end;
end;
DBT_DEVICEREMOVECOMPLETE : begin
if lpdb^.dbch_devicetype = DBT_DEVTYP_VOLUME then begin
lpdbv := PDEV_BROADCAST_VOLUME(Msg.dwData);
if (lpdbv^.dbcv_flags and DBTF_MEDIA) = 1 then
if Assigned(fAfterRemove) then
Application.MessageBox (' CDROM Open.',
'CDROM Information.',
MB_OK);
end;
end;
end;
end;
{ get Handle to a CD-player}
function TCDEvents.GetDevice : word;
var OpenParms : TMCI_Open_Parms;
FID : Word;
begin
if not (csDesigning in ComponentState) then begin
if fID=0 then begin
FFlags := 0;
FFlags := mci_notify or mci_open_type or mci_open_shareable;
OpenParms.lpstrDeviceType := 'CDAudio';
OpenParms.dwCallback := 0;
fErrCode := mciSendCommand(0, mci_open, FFlags, Longint(@OpenParms));
if FErrCode = 0 then {device successfully opened}
begin
fID := OpenParms.wDeviceID;
end;
end;
Result := fID;
end;
end;
{ Eject CDROM}
procedure TCDEvents.OpenDoor;
var
SetParms: TMCI_Set_Parms;
begin
FFlags := 0;
FFlags := mci_notify or mci_set_door_open;
SetParms.dwCallback := 0;
fErrCode := mciSendCommand(GetDevice, mci_Set, FFlags, Longint(@SetParms));
end;
{Close CDROM}
procedure TCDEvents.CloseDoor;
var
SetParm: TMCI_Set_Parms;
begin
FFlags := 0;
FFlags := mci_notify or mci_set_door_closed;
SetParm.dwCallback := 0;
fErrCode := mciSendCommand( GetDevice, mci_Set, FFlags, Longint(@SetParm) );
end;