This article shows how to detect when a CD has been inserted / removed.
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!!!';
DBT_DEVICEREMOVECOMPLETE : tmpSTr := 'CD REMOVED!!!';
end;
ShowMessage(tmpStr);
end;