5 The program automatically executes invalid menu mouse events
Procedure Tform1.mnotautorunclick (Sender:tobject); Var Reg:tregistry; Begin Reg:=tregistry.create; Try Reg.rootkey:=hkey_local_machine; if (Reg.openkey (' SOFTWARE\Microsoft\Windows\CurrentVersion\Run ', False)) =true Then Begin Add a value to the registry Reg.deletevalue (' Mystartup '); End Else MessageBox (Handle, ' open registry failed. ', ' wrong ', mb_ok+mb_iconerror); Finally Reg.closekey; Reg.free; End End |
6 The event procedure to open the CD-ROM drive submenu
Procedure Tform1.menuopencdrom (Sender:tobject); var I:integer; Begin With Sender as Tmenuitem doing begin If Menuindex = Mopencdrom.count-1 then//Determine if mouse clicks "All optical Drive" submenu items Begin For I: = 0 to Menuindex-1 do//Open all optical drives Begin Menuindex:=i; Mycdrom: =pchar (mopencdrom.items[i). Caption); Opencdrom (Mycdrom); End End Else Begin Mycdrom: =pchar (Mopencdrom.items[menuindex). Caption); Opencdrom (Mycdrom); End End |
7 Turn off the Optical Drive submenu event procedure
Procedure Tform1.menuclosecdrom (Sender:tobject); var I:integer; Begin With Sender as Tmenuitem doing begin If Menuindex = Mclosecdrom.count-1 then//Determine if mouse clicks "All optical Drive" submenu items Begin For I: = 0 to Menuindex-1 do////Turn off all optical drives Begin Mycdrom: =pchar (mclosecdrom.items[i). Caption); Closecdrom (Mycdrom); End End Else Mycdrom: =pchar (Mclosecdrom.items[menuindex). Caption); Closecdrom (Mycdrom); End End |
8 Shutdown Control Procedure submenu event procedure:
Procedure Tform1.mcloseappclick (Sender:tobject); Begin Application.terminate; program termination End |
Through the above functions and processes to achieve the control of Light drive, run the following program, with the right mouse button click on the window, pop-up Figure 2 menu effect, select the switch to control the CD-ROM drive, it is clear that the CD-ROM drive box began to be at the mercy of the program. The program can be further modified to hide its form, put into the status bar, the realization of the program tray function, due to space, this part is omitted.
This program Windows 2000 operating system + Delphi 5.0 implementation and debugging through.
Figure 2 Effect diagram of the final pop-up menu