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