1 2 unit Unit1; 3 4 interface 5 6 uses 7 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; 8 9 type 10 TForm1 = class(TForm) 11 procedure CDROM_Notification(var msg : TMessage); 12 message WM_DEVICECHANGE; 13 private 14 { private declarations } 15 public 16 { public declarations } 17 end; 18 19 var 20 Form1: TForm1; 21 22 implementation 23 24 {$R *.DFM} 25 26 const 27 CD_OUTPUT = $8004; 28 CD_INPUT = $8000; 29 30 procedure TForm1.CDROM_Notification(var msg : TMessage); 31 begin 32 if msg.wParam = CD_INPUT then 33 ShowMessage('There is a new CD.') 34 else 35 if msg.wParam = CD_OUTPUT then 36 ShowMessage('CD was ejected.'); 37 end;