I've had this problem for a while now but I have to remedy it as I must tackle it now. I'm trying to detect when a device is connected to the system in windows 7 and I receive the WM_DEVICECHANGE just fine, however the message in wParam is always DBT_DEVNODES_CHANGED. Never a DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE. I have had no luck googling thus far so I'm hoping someone will point me in the right direction before I find something in a few hours time :) Thanks for ya time.
相关问题
- Sorting 3 numbers without branching [closed]
- QML: Cannot read property 'xxx' of undefin
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
The documentation states that the DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE events should be received by default. The application can register to receive more detailed events by calling the RegisterDeviceNotification function. Hopefully you will receive the events you need after registering your app. Be sure to call UnregisterDeviceNotification upon closedown.
RegisterDeviceNotification reference:
http://msdn.microsoft.com/en-us/library/aa363431%28v=VS.85%29.aspx
P/Invoke Signature:
http://pinvoke.net/default.aspx/user32.RegisterDeviceNotification
UnregisterDeviceNotification reference:
http://msdn.microsoft.com/en-us/library/aa363475%28v=VS.85%29.aspx
P/Invoke Signature:
http://pinvoke.net/default.aspx/user32.UnregisterDeviceNotification
Thanks very much Fletcher. I have succeded in doing this for Qt4. Qt4(.6.3) users can add the
#include
files as normal but you will need to add some#defines
to your .h file:so that the windows data types like
DEV_BROADCAST_HEADER
can be recognised. Also the version number I guess depends on your windows platform but not sure (I use win 7 atm). Also don't forget to add the libraries to your .pro filesLIBS += "C:\Qt\2010.04\mingw\lib\<library_file>"
if you installed in the default position that is.