最終更新:2017-10-17 (火) 15:01:42 (2375d)
WM_DEVICECHANGE
Top / WM_DEVICECHANGE
Notifies an application of a change to the hardware configuration of a device or the computer.
A window receives this message through its WindowProc function.
https://msdn.microsoft.com/ja-jp/library/windows/desktop/aa363480(v=vs.85).aspx
パラメータ
LRESULT CALLBACK WindowProc(HWND hwnd, // handle to window UINT uMsg, // WM_DEVICECHANGE WPARAM wParam, // device-change event LPARAM lParam ); // event-specific data
uMsg?
wParam
DBT_DEVNODES_CHANGED 0x0007 A device has been added to or removed from the system. DBT_DEVICEARRIVAL 0x8000 (32768) A device or piece of media has been inserted and is now available. DBT_DEVICEQUERYREMOVE? 0x8001 Permission is requested to remove a device or piece of media. Any application can deny this request and cancel the removal. DBT_DEVICEQUERYREMOVEFAILED? 0x8002 A request to remove a device or piece of media has been canceled. DBT_DEVICEREMOVEPENDING? 0x8003 A device or piece of media is about to be removed. Cannot be denied. DBT_DEVICEREMOVECOMPLETE? 0x8004 A device or piece of media has been removed. DBT_DEVICETYPESPECIFIC? 0x8005 A device-specific event has occurred.
Hardware Helper Library for C#
- http://www.codeproject.com/Articles/21503/Hardware-Helper-Library-for-C
- when the WM_DEVICECHANGE message arrives, we simply reload the entire list. There is no fancy method of determining which device was added or removed at this time,
Detecting Hardware Insertion and/or Removal
- http://www.codeproject.com/Articles/14500/Detecting-Hardware-Insertion-and-or-Removal
- A user-mode application to detect hardware add/remove with WM_DEVICECHANGE and RegisterDeviceNotification()
- by default, Windows OS will only post WM_DEVICECHANGE to
- All applications with a top-level window, and
- Only upon port and volume change.
メモ
- USBメモリを挿した時にはDBT_DEVICEARRIVAL/DBT_DEVICEREMOVECOMPLETE?が発生した。
- マウス/Webカメラの時にはDBT_DEVNODES_CHANGEDしか発生しなかった。
- RegisterDeviceNotificationでGUID_DEVINTERFACE_USB_DEVICEを登録するとDBT_DEVICEARRIVAL/DBT_DEVICEREMOVECOMPLETE?がくるようになる。