Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Nov : Re: Detecting removable media arrival/removal

www.cryer.info
Managed Newsgroup Archive

Re: Detecting removable media arrival/removal

Subject:Re: Detecting removable media arrival/removal
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Wed, 8 Nov 2006 14:16:14

"Ricardo Villela Coppola" <coppola@csp.com.br> wrote in message
news:45507b4b@newsgroups.borland.com...

>    FRegInHnd := RegisterDeviceNotification(Application.Handle, dbi,
> DEVICE_NOTIFY_WINDOW_HANDLE);
<snip>
> procedure TFormMessages.WmDeviceChange(var Message: TWMDeviceChange);

You are telling the OS to send the notifications to the TApplication's
hidden window, however you are trying to catch the message in the TForm
window instead.

If you keep using TApplication.Handle, then you will have to call
TApplication.HookMainWindow() in order to catch messages that are sent to
that window.  Otherwise, use your form's own Handle instead (and then
override CreateWnd() so tht you can handle situations where the TForm's
window is recreated dynamically at runtime).  Or use AllocateHWnd() to
create a new hidden window just for the notifications to use.

> It detects device removal and arrival but not the media.

That is probably because the media notifications are going to a different
window.  Device notifications are broadcasted to all top-level windows, so
your TForm receives those notifications directly.  But you are registering
for media notifications separately, and then trying to processing them in
the wrong window.


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive