Pop-up and close CD-ROM in Delphi Program

Source: Internet
Author: User

To control the pop-up and close of the CD-ROM In the Delphi Program, you can use the media control interface function of the mmsystem. Pas unit. Two functions can achieve the same effect. One is the mcisendcommand function, and the other is the mcisendstring function. The opencddrive functions written using these two functions are as follows.

1. Use mcisendcommand:

Function opencddrive (isopen: Boolean; drivename: Char = #0): Boolean;
VaR
OP: tmci_open_parms;
Flags: longword;
Begin
Fillchar (OP, sizeof (tmci_open_parms), 0 );
Op. lpstrdevicetype: = pchar (mci_devtype_cd_audio );
Flags: = mci_open_type or mci_open_type_id;
If drivename <> #0 then
Begin
Op. lpstrelementname: = pchar (drivename + ':');
Flags: = flags or mci_open_element;
End;
Result: = mcisendcommand (0, mci_open, flags, longword (@ OP) = 0;
If not result then exit;
If isopen then
Mcisendcommand (op. wdeviceid, mci_set, mci_set_door_open, 0)
Else
Mcisendcommand (op. wdeviceid, mci_set, mci_set_door_closed, 0 );
Mcisendcommand (op. wdeviceid, mci_close, mci_wait, 0 );
End;

2. Use mcisendstring:

Function opencddrive (isopen: Boolean; drivename: Char = #0): Boolean;
VaR
S: string;
Begin
If isopen then s: = 'open'
Else S: = 'closed ';
If drivename = #0 then
Result: = mcisendstring (pchar ('set cdaudio door '+ S), nil, 0, 0) = 0
Else
Begin
Result: = mcisendstring (pchar ('open' + drivename + ': Type cdaudio alias CDROM'), nil, 0, 0) = 0; If result then begin
Mcisendstring (pchar ('set CDROM door '+ S), nil, 0, 0 );
Mcisendstring ('close CDROM ', nil, 0, 0); end;
End;
End;

The opencddrive function has 2 parameters, isopen is true to bring up the CD-ROM, false to turn off rd_rom; drivename is the CD-ROM drive name, default is #0. True is returned. Otherwise, the operation fails.

Turn on and off the default CD-ROM, that is, the first CD-ROM drive can use:

Opencddrive (true); and opencddrive (false );

Using the CD-ROM drive name call can be (assuming the CD-ROM drive name is F :"):

Opencddrive (true, 'F'); and opencddrive (false, 'F ');

If there is an error please correct: maozefa@hotmail.com

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.