DelphiFAQ Home Search:
General :: Windows :: Programming :: Windows with Delphi :: Windows Filesystem
File related questions and answers. File operations, attributes, system dialogs, hard disk handling.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

CDROM notification (CDROM inserted or ejected)

Question:

When the user inserts a CD in Drive E:, my application should do something. How can I get notified about a new CD being inserted?

Answer:

When a new CD is inserted, Windows posts to all processes the WM_DEVICECHANGE message. Its wParam value contain the information you need:

OUTPUT -> $8004;
INSERT -> $8000;

unit Unit1;
 
 interface
 
 uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
 
 type
   TForm1 = class(TForm)
     procedure CDROM_Notification(var msg : TMessage);
       message WM_DEVICECHANGE;
   private
     { private declarations }
   public
     { public declarations }
   end;
 
 var
   Form1: TForm1;
 
 implementation
 
 {$R *.DFM}
 
 const
   CD_OUTPUT = $8004;
   CD_INPUT  = $8000;
 
 procedure TForm1.CDROM_Notification(var msg : TMessage);
 begin
   if msg.wParam = CD_INPUT then
     ShowMessage('There is a new CD.')
   else
   if msg.wParam = CD_OUTPUT then
     ShowMessage('CD was ejected.');
 end;
 
 end.

Generated 20:02:26 on Oct 16, 2017