unit uDriveTools;
interface
uses Windows,SysUtils,MMSystem;
function CloseCD(Drive:Char):Boolean;
function OpenCD(Drive:Char):Boolean;
implementation
function OpenCD(Drive:Char):Boolean;
var Res:MciError;
; ; OpenParm:TMCI_Open_Parms;
; ; Flags
Word;
; ; s:string;
; ; DeviceID:Word;
begin
; Result:=false;
; s:=Drive+':';
; Flags:=mci_Open_Type or Mci_Open_Element;
; With OpenParm do
; begin
; ; dwCallBack:=0;
; ; lpstrDeviceType:='CDAudio';
; ; lpstrElementName:=PChar(s);
; end;
; Res:=mciSendCommand(0,mci_Open,Flags,LongInt(@OpenParm));
; If RES<>0 then exit;
; DeviceID:=OpenParm.wDeviceID;
; try
; ; Res:=mciSendCommand(DeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0);
; ; IF RES=0 then exit;
; ; Result:=True;
; finally
; ; mciSendCommand(DeviceID,mci_Close,Flags,Longint(@OpenParm));
; end;
end;
function CloseCD(Drive:Char):Boolean;
var Res:MciError;
; ; OpenParm:TMCI_OPEN_PARMS;
; ; Flags
Word;
; ; s:string;
; ; DeviceID:Word;
begin
; Result:=False;
; S:=Drive+':';
; Flags:=mci_Open_Type or Mci_Open_Element;
; With OpenParm do
; begin
; ; dwCallBack:=0;
; ; lpstrDeviceType:='CDAudio';
; ; lpstrElementName:=PChar(s);
; end;
; Res:=mciSendCommand(0,mci_Open,Flags,LongInt(@OpenParm));
; if Res<>0 then exit;
; DeviceID:=OpenParm.wDeviceID;
; try
; ; Res:=mciSendCommand(DeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);
; ; If Res=0 then exit;
; ; Result:=True;
; finally
; ; mciSendCommand(DeviceID,mci_Close,Flags,LongInt(@OpenParm));
; end;
end;
end.
应用:
procedure TForm1.Button1Click(Sender: TObject);
begin
; OpenCD('E');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
; CloseCD('E');
end;