uses mmSystem; procedure CDRomOpen(bOpenDrive:boolean; cDrive:char); //uses mmSystem var open:MCI_OPEN_PARMS; status:MCI_STATUS_PARMS; flags:dword; szDriveName:array[0..3]of char; begin strcopy(szDriveName,'?:'); ZeroMemory(@open,sizeof(MCI_OPEN_PARMS)); open.lpstrDeviceType:=LPCSTR(MCI_DEVTYPE_CD_AUDIO); szDriveName[0]:=cDrive; open.lpstrElementName:=szDriveName; flags:=MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or MCI_OPEN_ELEMENT or MCI_OPEN_SHAREABLE; if mciSendCommand(0,MCI_OPEN,flags,LongWord(@open))=0 then begin status.dwItem:=MCI_STATUS_READY; if (bOpenDrive) then mciSendCommand(open.wDeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0) else mciSendCommand(open.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0); mciSendCommand(open.wDeviceID,MCI_CLOSE,MCI_WAIT,0); end; end; procedure TForm1.BitBtn1Click(Sender: TObject); begin CDRomOpen(true,'I'); // open cd end;procedure TForm1.BitBtn2Click(Sender: TObject); begin CDRomOpen(false,'I'); // Close cd end;
procedure CDRomOpen(bOpenDrive:boolean; cDrive:char); //uses mmSystem
var open:MCI_OPEN_PARMS;
status:MCI_STATUS_PARMS;
flags:dword;
szDriveName:array[0..3]of char;
begin
strcopy(szDriveName,'?:');
ZeroMemory(@open,sizeof(MCI_OPEN_PARMS));
open.lpstrDeviceType:=LPCSTR(MCI_DEVTYPE_CD_AUDIO);
szDriveName[0]:=cDrive;
open.lpstrElementName:=szDriveName;
flags:=MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or MCI_OPEN_ELEMENT or MCI_OPEN_SHAREABLE;
if mciSendCommand(0,MCI_OPEN,flags,LongWord(@open))=0 then
begin
status.dwItem:=MCI_STATUS_READY;
if (bOpenDrive) then mciSendCommand(open.wDeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0)
else mciSendCommand(open.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);
mciSendCommand(open.wDeviceID,MCI_CLOSE,MCI_WAIT,0);
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
CDRomOpen(true,'I'); // open cd
end;procedure TForm1.BitBtn2Click(Sender: TObject);
begin
CDRomOpen(false,'I'); // Close cd
end;