Thema: Delphi cdrom laufwerk auswerfen

Einzelnen Beitrag anzeigen

Daniel B
(Gast)

n/a Beiträge
 
#2
  Alt 5. Jul 2003, 11:29
Hallo,

unit "MMSYstem" in den Uses aufnehmen!
Delphi-Quellcode:
procedure OpenCdTray(AOpen: Boolean);
var
  DeviceID: MCIDEVICEID;
  OpenParams: TMCI_OPEN_PARMS;
  Error: LongInt;
  ErrorString: array[0..MAXERRORLENGTH - 1] of Char;
begin
  OpenParams.lpstrDeviceType := 'cdaudio';
  Error := mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE, longint(@OpenParams));

  if Error <> 0 then
  begin
    MciGetErrorString(Error, ErrorString, MAXERRORLENGTH - 1);
    ShowMessage(ErrorString);
    Exit;
  end;

  DeviceID := mciGetDeviceID('cdaudio');

  if AOpen then
  begin
    Error := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0)
  end
  else
  begin
    mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
  end;

  if Error <> 0 then
  begin
    MciGetErrorString(Error, ErrorString, MAXERRORLENGTH - 1);
    ShowMessage(ErrorString);
  end;

  Error := mciSendCommand(DeviceID, MCI_CLOSE, 0, 0);

  if Error <> 0 then
  begin
    MciGetErrorString(Error, ErrorString, MAXERRORLENGTH - 1);
    ShowMessage(ErrorString);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  OpenCDTray(True);
end;
Grüsse, Daniel