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; |
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; |
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("SoftwareMicrosoftWindowsCurrentVersionRun",False))=True then begin // 在注册表中添加数值 Reg.WriteString("MyStartup",Application.ExeName); end else MessageBox(Handle,"打开注册表失败。","错误",MB_OK+MB_ICONERROR); finally Reg.CloseKey; Reg.Free; end; end; |