lung | Bin, j'ai ca pour commencer :
Code :
- function IsCdOpen(Drive:Char):Boolean;
- const MAXLENGTH = 255;
- var S:Pchar;
- Rep:Cardinal;
- begin
- Result := False;
- try
- GetMem(S,MAXLENGTH);
- Rep := MciSendString(PChar('Open CdAudio Alias cd Wait Shareable'), S, MAXLENGTH, Handle);
- if Rep<>0 then begin
- MciGetErrorString(Rep,S,MAXLENGTH);
- Application.MessageBox(S,0,MB_ICONERROR);
- Exit;
- end;
- Rep := MciSendString(PChar('Status cd Mode'), S, MAXLENGTH, Handle);
- if Rep<>0 then begin
- MciGetErrorString(Rep,S,MAXLENGTH);
- Application.MessageBox(S,0,MB_ICONERROR);
- Exit;
- end;
- if S='stopped' then Result := False
- else Result := True;
- Rep := MciSendString(PChar('Close cd'), S, MAXLENGTH, Handle);
- if Rep<>0 then begin
- MciGetErrorString(Rep,S,MAXLENGTH);
- Application.MessageBox(S,0,MB_ICONERROR);
- Exit;
- end;
- Finally
- FreeMem(S,MAXLENGTH);
- end;
- end;
- function IsMediaPresent:Boolean;
- const MAXLENGTH = 255;
- var S:Pchar;
- Rep:Cardinal;
- begin
- Result := False;
- try
- GetMem(S,MAXLENGTH);
- Rep := MciSendString(PChar('Open CdAudio Alias cd Wait Shareable'), S, MAXLENGTH, Handle);
- if Rep<>0 then begin
- MciGetErrorString(Rep,S,MAXLENGTH);
- Application.MessageBox(S,0,MB_ICONERROR);
- Exit;
- end;
- Rep := MciSendString(PChar('Status cd Media Present'), S, MAXLENGTH, Handle);
- if Rep<>0 then begin
- MciGetErrorString(Rep,S,MAXLENGTH);
- Application.MessageBox(S,0,MB_ICONERROR);
- Exit;
- end;
- if S = 'true' then Result := True
- else Result:= False;
- Rep := MciSendString(PChar('Close cd'), S, MAXLENGTH, Handle);
- if Rep<>0 then begin
- MciGetErrorString(Rep,S,MAXLENGTH);
- Application.MessageBox(S,0,MB_ICONERROR);
- Exit;
- end;
- Finally
- FreeMem(S,MAXLENGTH);
- end;
- end;
|
Ca détecte (en théorie, je ne l'ai pas testé) si le lecteur est ouvert. J'en ai un autre qui ouvre et ferme le lecteur, si ca t'interresse.
|