Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
CDROM notification (CDROM inserted or ejected)
2 comments. Current rating: (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
public
end;
var
Form1: TForm1;
implementation
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:
|
|
|
|
Its works good
|
|
|
|
|
How I can receive notification about new CD with out window. For example I develop Windows service? Thanks...
|
|