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

Source: Internet
Author: User
Tags manual
This paper introduces the main technology and method of opening CD-ROM in Delphi programming environment, the program is hosted in the status bar by pallet, which can be set up to boot with the system, not only to control an optical drive, but also to dynamically detect the number of optical drives on a computer, create the corresponding control menu, Implement selective control of the optical drive.

Keyword Delphi program CD-ROM control popup menu process events

Introduction

Normally, we turn on and off the optical drive by pressing the switch button on the optical drive to achieve the But sometimes manual mode is very inconvenient, especially in a computer installation of more than one optical drive, while the loss of optical drive in the manual mode is also the largest, Delphi is a powerful and easy programming tools, Can not use the programming method to replace the manual operation? Through groping and practice finally will this idea use Delphi programming to realize, this program not only can control an optical drive, but also can selectively control an optical drive and all optical drive open and close, this to those who operate multiple optical drive and lazy to bend computer person indeed will be convenient many.

Programming Ideas

Programming Ideas: Control the optical drive through pop-up menus and events.

1, the Realization of pop-up menu

Run Delphi and create a new project, in the uses part of the reference registry, MMSystem two cell files, add a name in the form called Popmenucdctrl pop-up menu build, and Add 6 menu items, form TForm1 PopupMenu Xiang is assigned to the Popmenucdctrl,popmenucdctrl name and primary property as shown in Table 1.

Table 1 Tpopupmenu Build property sheet


Name

Component type

Component Caption

Major processes and events

Description

Mmenutitle

Tmenuitem

= = Drive Control = =

No

pop-up menu label

Mopencdrom

Tmenuitem

Open the CDROM box.

Generate Submenus (

Open the CD-ROM drive sub menu

Mclosecdrom

Tmenuitem

Close CDROM box

Generate submenus

Turn off the optical Drive sub Menu

Mautorun

Tmenuitem

To perform at startup

Mautorunclick

Boot run

Mnotautorun

Tmenuitem

Automatic execution is invalid

Setcdautorun (False)

Cancel the power-on operation

Mcloseapp

Tmenuitem

Shutdown Control Program

Application.terminate;

Shutdown Control Program

The pop-up menu effect is set as shown in Figure 1, where mopencdrom (open cdrom box) and Mclosecdrom (Close CDROM box) menu will automatically generate the corresponding menu columns according to the number of CD-ROM drives in the computer.



Figure 1 pop-up menu effect chart

2, declared variables and functions:

... ...

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
Form1:tform1;
Mydrive:char;
Mycdrom:pchar;
Tmppopmenu1,tmppopmenu2:tmenuitem;
function Opencdrom (Drive:pchar): Boolean;
function Closecdrom (Drive:pchar): Boolean;
Implementation
... ...

1) List the number of optical drives and the Build submenu

Procedure Tform1.popupmenu1popup (Sender:tobject);
var Drive:char;
Begin
Mopencdrom.clear; Clear Open Optical Drive submenu items
Mclosecdrom.clear; Clear Open Optical Drive submenu items
List the number of optical drives and the Build submenu

For drive:= ' A ' and ' Z ' do
Begin
Case GetDriveType (Pchar (drive+ ': \)) of
Drive_removable:
mydrive:=drive;
Drive_fixed:
mydrive:=drive;
Drive_cdrom:
Begin
mydrive:=drive;
Tmppopmenu1:=tmenuitem.create (Self);
Tmppopmenu1. autohotkeys:=mamanual;
Tmppopmenu1. OnClick: = Menuopencdrom;
Mopencdrom.add (TMPPOPMENU1);
Tmppopmenu1. Caption: =uppercase (mydrive) + ': ';
Tmppopmenu2:=tmenuitem.create (Self);
Tmppopmenu2. autohotkeys:=mamanual;
Tmppopmenu2. OnClick: = Menuclosecdrom;
Mclosecdrom.add (TMPPOPMENU2);
Tmppopmenu2. Caption: =uppercase (mydrive) + ': ';
End

Drive_ramdisk:
mydrive:=drive;
Drive_remote:
mydrive:=drive;
End
End

When more than 1 optical drives generate "All optical drives" control menu items

If Mopencdrom.count > 1 Then
Begin
Tmppopmenu1:=tmenuitem.create (Self);
Tmppopmenu1. caption:= ' all optical drives ';
Tmppopmenu1. OnClick: = Menuopencdrom;
Mopencdrom.add (TMPPOPMENU1);
Tmppopmenu2:=tmenuitem.create (Self);
Tmppopmenu2. caption:= ' all optical drives ';
Tmppopmenu2. OnClick: = Menuclosecdrom;
Mclosecdrom.add (TMPPOPMENU2);
End

End

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.