2007. december 21., péntek

How to detect if a CD has been inserted or removed into/ from a drive


Problem/Question/Abstract:

How to detect if a CD has been inserted or removed into/ from a drive

Answer:

{ ... }
type
  TForm1 = class(TForm)
  private
    { private declarations }
    procedure WMDeviceChange(var Msg: TMessage); message WM_DeviceChange;
  public
    { public declarations }
  end;

procedure TForm1.WMDeviceChange(var Msg: TMessage);
const
  DBT_QUERYCHANGECONFIG = $0017;
  DBT_CONFIGCHANGED = $0018;
  DBT_CONFIGCHANGECANCELED = $0019;
  DBT_DEVICEARRIVAL = $8000;
  DBT_DEVICEQUERYREMOVE = $8001;
  DBT_DEVICEQUERYREMOVEFAILED = $8002;
  DBT_DEVICEREMOVEPENDING = $8003;
  DBT_DEVICEREMOVECOMPLETE = $8004;
  DBT_DEVICETYPESPECIFIC = $8005;
  DBT_USERDEFINED = $FFFF;
var
  tmpStr: string;
begin
  inherited
    case Msg.wParam of
    DBT_DEVICEARRIVAL:
      tmpStr := 'CD inserted in drive';
    DBT_DEVICEREMOVECOMPLETE:
      tmpSTr := 'CD removed from drive';
  end;
  ShowMessage(tmpStr);
end;

Nincsenek megjegyzések:

Megjegyzés küldése