看这段代码,可以弹出不同的光驱。
uses mmSysTem;
procedure CDRomOpen(bOpenDrive: Boolean; cDrive: Char);
var
o: MCI_OPEN_PARMS;
status: MCI_STATUS_PARMS;
flags: DWord;
szDriveName: array[0..3] of Char;
begin
szDriveName := '?:';
ZeroMemory(@o, SizeOf(MCI_OPEN_PARMS));
szDriveName[0] := cDrive;
o.lpstrDeviceType := PChar(MCI_DEVTYPE_CD_AUDIO);
o.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, Cardinal(@o)) = 0 then
begin
status.dwItem := MCI_STATUS_READY;
if bOpenDrive then
mciSendCommand(o.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0)
else
mciSendCommand(o.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
mciSendCommand(o.wDeviceID, MCI_CLOSE, MCI_WAIT, 0);
end;
end;