DelphiFAQ Home Search:

CDROM notification (CDROM inserted or ejected)

 

comments2 comments. Current rating: 4 stars (2 votes). Leave comments and/ or rate it.

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.

Comments:

2006-03-23, 20:52:32
anonymous from Indonesia  
rating
Its works good
2006-08-03, 04:23:46
anonymous from United Kingdom  
rating
How I can receive notification about new CD with out window. For example I develop Windows service? Thanks...

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.