FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour WM_DEVICECHANGE ???????
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
WM_DEVICECHANGE ???????
Posted: Wed Mar 24, 2010 02:16 AM

How capture this event in fivewin.

i wanna know when is pluged a pen drive or other hardware disk

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

someone can help me ?

Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: WM_DEVICECHANGE ???????
Posted: Wed Mar 24, 2010 05:02 PM

up !

Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: WM_DEVICECHANGE ???????
Posted: Sat Mar 27, 2010 04:57 AM

go top

Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: WM_DEVICECHANGE ???????
Posted: Mon Mar 29, 2010 12:04 AM

up. :roll:

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: WM_DEVICECHANGE ???????
Posted: Mon Mar 29, 2010 05:09 AM
Dear Mr.Lailton,

May be useful for you

To detect the Hardware device change, the operating system will send a WM_DEVICECHANGE message to the application when a device change is detected. All we
need to do is handle this message in the window procedure of the application. When the window procedure is called the parameters passed will be as follows.

Parameter & Description
HWND hWnd Handle to the window
UINT uiMessage WM_DEVICECHANGE
WPARAM wParam Device-change event
LPARAM lParam Event-specific data

This means, hWnd will be the handle to our window, uiMessage will be the window
message WM_DEVICECHANGE, wParam will be the device-change event such as
DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE, and finally lParam is a pointer to
the device broadcast header. Below is an example of how you could implement a handler
for WM_DEVICECHANGE

Code (fw): Select all Collapse
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch (uiMsg)
  {
     case WM_DEVICECHANGE:
     {
        PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR) lParam;
        switch (wParam)
        {
           case DBT_DEVICEARRIVAL:
              MessageBox(hWnd, "A device has been inserted.", "USB Notice", MB_OK);
           break;
           case DBT_DEVICEREMOVECOMPLETE:
              MessageBox(hWnd, "A device has been removed.", "USB Notice", MB_OK);
           break;
        }
     }
     break;
     default:
        return DefWindowProc(hWnd, uiMsg, wParam, lParam);
     break;
  }
  return 0;
}


This code will display a message box when a new device is inserted or removed from the
system, with an appropriate message.

Regards
Anser
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: WM_DEVICECHANGE ???????
Posted: Mon Mar 29, 2010 05:43 AM
Lailton

other way

As a start you could inherit a new Class TMyWindow FROM TWindow and redefine the Method HandleEvent() to process WM_DEVICECHANGE message

like this
Code (fw): Select all Collapse
function Main()

   local oWnd := TMyWindow():New()

   oWnd:Activate()

return nil

CLASS TMyWindow FROM TWindow

   CLASSDATA lRegistered

   METHOD HandleEvent( nMsg, nWParam, nLParam ) 

ENDCLASS

METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMyWindow

   if nMsg == WM_DEVICECHANGE 
      MsgBeep() // ok, we are receiving WM_DEVICECHANGE  messages
   endif   

return Super:HandleEvent( nMsg, nWParam, nLParam )
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: WM_DEVICECHANGE ???????
Posted: Mon Mar 29, 2010 11:29 AM

i will try this way

thanks so much for yours reply.

Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: WM_DEVICECHANGE ???????
Posted: Tue May 30, 2017 11:27 AM

Dear Anser,

could you post a small and whole sample ?

Thanks in advance !

Best regards,

Posts: 1364
Joined: Wed Jun 21, 2006 12:39 AM
Re: WM_DEVICECHANGE ???????
Posted: Tue May 30, 2017 02:04 PM

What value WM_DEVICECHANGE has ?. Thank you

Saludos

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: WM_DEVICECHANGE ???????
Posted: Tue May 30, 2017 02:17 PM

Try

WM_DEVICECHANGE = 537

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: WM_DEVICECHANGE ???????
Posted: Wed May 31, 2017 09:38 AM

Dear Anser,

please, could you post a small and whole sample ?

Thanks in advance !

Best regards,

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: WM_DEVICECHANGE ???????
Posted: Fri Jun 02, 2017 04:41 AM
Baxajaun wrote:Dear Anser,

please, could you post a small and whole sample ?

Thanks in advance !

Best regards,


I tried this for experimentation long time back. Unfortunately, as of now, I am unable to locate the sample on my hard drive.

By the way did you try to use the sample posted by Mr.Daniel ? For me, his sample is working fine here on both Harbour and xHarbour.

Instead of return Super:HandleEvent( nMsg, nWParam, nLParam )
change it to
return ::HandleEvent( nMsg, nWParam, nLParam )

Continue the discussion