Home   |   Software   |   Practical Jokes   |   Code Corner   |   Workshops


Delphi Secret #5

Opening or Closing the CD Tray
 
 
     In order to open or close the CD tray, one must create a mediaplayer object. This object requires the MMSystem library. In order to change the disk drive to open, change the FileName of the mediaplayer object. If you are wanting to open the CD tray, use the MCI_SET_DOOR_OPEN command. If you are wanting to close the CD tray, use the MCI_SET_DOOR_CLOSED command.

Code:
var
  mp : TMediaPlayer;
begin
  Application.ProcessMessages;
  mp := TMediaPlayer.Create(nil);
  mp.Visible := false;
  mp.Parent := Application.MainForm;
  mp.Shareable := true;
  mp.DeviceType := dtCDAudio;
  mp.FileName := 'D:';
  mp.Open;
  Application.ProcessMessages;
  mciSendCommand(mp.DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
  Application.ProcessMessages;
  mp.Close;
  Application.ProcessMessages;
  mp.free;
end;



This page was developed by FoxWare Design & Support.
Hosted by www.Geocities.ws

1