Главная страница | назад





Article #17861: How can I close the CD Tray in code?

 Question and Answer Database
FAQ2861D.txt How can I close the CD Tray in code?
Category :Windows API
Platform :All
Product :All 32 bit
Question:
How can I close the CD Tray in code?
Answer:
Make a call to the MMSystem function mciSendCommand
sending the MCI_SET_DOOR_CLOSED command.
Example:
uses MMSystem;
procedure CloseCD(Drive : char);
var
mp : TMediaPlayer;
begin
result := false;
Application.ProcessMessages;
mp := TMediaPlayer.Create(nil);
mp.Visible := false;
mp.Parent := Application.MainForm;
mp.Shareable := true;
mp.DeviceType := dtCDAudio;
mp.FileName := Drive + ':';
mp.Open;
Application.ProcessMessages;
mciSendCommand(mp.DeviceID,
MCI_SET, MCI_SET_DOOR_CLOSED, 0);
Application.ProcessMessages;
mp.Close;
Application.ProcessMessages;
mp.free;
result := true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CloseCD('D');
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99