2)打開CDROM盒的函數
function OpenCDROM(Drive:pChar):Boolean; // 打開CDROM
var
Res:MciError;
OpenParm:TMCI_OPEN_Parms;
Flags:Dword;
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;
3)關閉CDROM盒的函數
function CloseCDROM(Drive:pChar):Boolean; // 關閉CDROM
var
Res:MciError;
OpenParm:TMCI_OPEN_Parms;
Flags:Dword;
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;
4)置程序啟動時執行菜單鼠標事件
procedure TForm1.mAutorunClick(Sender: TObject);
var
Reg: TRegistry;
begin
if Application.ExeName='' then // 判斷應用程序文件名是否為空
begin
MessageBox(Handle,'應用程序名稱不可以為空。','錯誤',MB_OK+MB_ICONERROR);
Exit;
end;
// 初始化AppFileName
//GetMem(Application.ExeName,256);
// edit1.text.GetTextBuf(AppFileName,256);
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if (Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run',False))=True then
begin
// 在注冊表中添加數值
Reg.WriteString('MyStartup',Application.ExeName);
end
else
MessageBox(Handle,'打開注冊表失敗。','錯誤',MB_OK+MB_ICONERROR);
finally
Reg.CloseKey;
Reg.Free;
end;
end;