通常
編程思路
編程思路
運行Delphi並新建一個工程
表
設置後的彈出菜單效果如圖
圖
… …
procedure mCloseAppClick(Sender: TObject);
procedure mAutorunClick(Sender: TObject);
procedure mNotautorunClick(Sender: TObject);
procedure PopmenuCDctrlPopup(Sender: TObject);
private
{ Private declarations }
procedure MenuOpenCdrom(Sender : TObject);
procedure MenuCloseCdrom(Sender : TObject);
var
Form
MYDRIVE:char;
Mycdrom:pchar;
tmppopmenu
function OpenCDROM(Drive:pChar):Boolean;
function CloseCDROM(Drive:pChar):Boolean;
implementation
… …
procedure TForm
var Drive :char;
begin;
mOpenCdrom
mCloseCdrom
//列出光驅數目和生成子菜單
for Drive:=
begin
Case GetDriveType(Pchar(Drive+
DRIVE_REMOVABLE:
MyDrive:=Drive;
DRIVE_FIXED:
MyDrive:=Drive;
DRIVE_CDROM:
begin
MyDrive:=Drive;
tmppopmenu
tmppopmenu
tmppopmenu
mOpenCDROM
tmppopmenu
tmppopmenu
tmppopmenu
tmppopmenu
mCloseCDROM
tmppopmenu
end;
DRIVE_RAMDISK:
MyDrive:=Drive;
DRIVE_REMOTE:
MyDrive:=Drive;
end;
end;
//當光驅多於
if mOpenCDROM
begin
tmppopmenu
tmppopmenu
tmppopmenu
mOpenCDROM
tmppopmenu
tmppopmenu
tmppopmenu
mCloseCDROM
end;
end;
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:=
lpstrDeviceType:=
lpstrElementName:=PChar(s);
end;
Res:=mciSendCommand(
If Res<>
DeviceID:=OpenParm
try
Res:=mciSendCommand(DeviceID
If Res=
Result:=True;
finally
mciSendCommand(DeviceID
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:=
lpstrDeviceType:=
lpstrElementName:=PChar(s);
end;
Res:=mciSendCommand(
If Res<>
DeviceID:=OpenParm
try
Res:=mciSendCommand(DeviceID
If Res=
Result:=True;
finally
mciSendCommand(DeviceID
end;
end;
procedure TForm
var
Reg: TRegistry;
begin
if Application
begin
MessageBox(Handle
Exit;
end;
// 初始化AppFileName
//GetMem(Application
// edit
Reg:=TRegistry
try
Reg
if (Reg
begin
// 在注冊表中添加數值
Reg
end
else
MessageBox(Handle
finally
Reg
Reg
end;
end;
procedure TForm
var
Reg: TRegistry;
begin
Reg:=TRegistry
try
Reg
if (Reg
begin
// 在注冊表中添加數值
Reg
end
else
MessageBox(Handle
finally
Reg
Reg
end;
end;
procedure TForm
var i:integer;
begin
with Sender as TMenuItem do begin
if Menuindex = mOpenCDROM
begin
for i :=
begin
// Menuindex:=i;
Mycdrom :=pchar(mopenCdrom
OpenCdrom(Mycdrom);
end;
end else
begin
Mycdrom :=pchar(mopenCdrom
OpenCdrom(Mycdrom);
end;
end;
procedure TForm
var i:integer;
begin
with Sender as TMenuItem do begin
if Menuindex = mCloseCDROM
begin
for i :=
begin
Mycdrom :=pchar(mCloseCdrom
CloseCdrom(Mycdrom);
end;
end else
Mycdrom :=pchar(mCloseCdrom
CloseCdrom(Mycdrom);
end;
end;
procedure TForm
begin
Application
end;
通過上述的函數和過程實現了對光驅的控制
本程序Windows
圖
From:http://tw.wingwit.com/Article/program/Delphi/201311/24757.html