Realization of switch control of optical drive box with Delphi (III.)

Source: Internet
Author: User
Tags count

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.