Know when a CD was inserted or removed

from the CD drive

 



It's easy if we capture the WM_DEVICECHANGE message . Put this line into private section of your form's declaration :

 

  private

    { Private declarations }

  procedure WMDeviceChange(var Message: TMessage);

  message WM_DEVICECHANGE;

…………………………………………….

 

procedure TForm1.WMDeviceChange(var Message: TMessage);

const

  CD_Inserted                = $8000;

  CD_ Removed                = $8004;

var

  Str : String;

begin

  inherited;

  case Message.wParam of

    CD_Inserted        : Str := 'CD Insert';

    CD_ Removed        : Str := 'CD Remove';

  end;

  ShowMessage(Str);

end;


Back Home Foward