private
{ Private declarations }
flag,control,hotkeyid,KeyId:integer;
wDeviceID
WORD;
o:TMCI_Open_Parms;
//p:TMCI_Play_Parms;
s:TMCI_Set_Parms;
g:TMCI_Generic_Parms;
public
{ Public declarations }
function CDPower:Boolean;
function OpenCDROM:Boolean;
function CloseCDROM:Boolean;
function OpenDriver:Boolean;
function CloseDriver:Boolean;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.CDPower:Boolean;
begin
Result:=true;
if flag=1 then
begin
if OpenCDROM()=false then
Result:=false;
end
else
begin
if CloseCDROM()=false then
Result:=false;
end;
flag:=not flag;
end;
//---------------------------------------------------------------------------
function TForm1.OpenCDROM:Boolean;
begin
Result:=false;
if OpenDriver=false then
exit;
s.dwCallback:=DWORD(Handle);
if mciSendCommand(wDeviceID,MCI_SET,MCI_WAIT or MCI_NOTIFY or MCI_SET_DOOR_OPEN,DWORD(PMCI_OPEN_PARMS(@s)))<>0 then
exit;
if CloseDriver=false then
exit;
Result:=true;;
end;
//---------------------------------------------------------------------------
function TForm1.CloseCDROM:Boolean;
begin
Result:=false;
if OpenDriver=false then
exit;
s.dwCallback:=DWORD(Handle);
if mciSendCommand(wDeviceID,MCI_SET,MCI_WAIT or MCI_NOTIFY or MCI_SET_DOOR_CLOSED,DWORD(PMCI_OPEN_PARMS(@s)))<>0 then
exit;
if CloseDriver=false then
exit;
Result:=true;
end;
//---------------------------------------------------------------------------
function TForm1.OpenDriver:Boolean;
begin
Result:=true;
with odo
begin
dwCallback:=0;
wDeviceID:=0;
lpstrDeviceType:='CDAudio';
lpstrAlias:=nil;
end;
if mciSendCommand(0,MCI_OPEN,DWORD(MCI_WAIT or MCI_NOTIFY or MCI_OPEN_TYPE or MCI_OPEN_SHAREABLE),DWORD(PMCI_OPEN_PARMS(@o)))<>0 then
Result:=false
else
wDeviceID:=o.wDeviceID;
end;
//---------------------------------------------------------------------------
function TForm1.CloseDriver:Boolean;
begin
Result:=true;
g.dwCallback:=DWORD(Handle);
if mciSendCommand(wDeviceID,MCI_CLOSE,MCI_WAIT or MCI_NOTIFY,DWORD(PMCI_OPEN_PARMS(@g)))<>0 then
Result:=false;
end;
//---------------------------------------------------------------------------
有点乱,但是就是这样,楼中几位兄台所说的办法,如果是CD-ROM设备已经被占用就不管用
了(比如说前台有一个CD播放器),还是试试我的办法吧。