This article was written to answer questions about how to detect when a USB flash disk is installed or removed to a computer on the Windows operating system. Detail the question here.
WM_DEVICECHANGE
WM_DEVICECHANGE message will be sent to top-level window when there are changes to existing hardware configuration on the computer. Some of the events leading WM_DEVICECHANGE sent, one of which, is the change in the removable storage media such as CD / DVD or USB flash disk.
Message handlers can use the wParam parameter to specify the type of device change events. Some of them are:
- DBT_DEVICEARRIVAL. Devices or media recently installed and ready for use.
- DBT_DEVICEREMOVECOMPLETE. Device or removable media success.
- DBT_DEVICEREMOVEPENDING. Devices or media success is delayed.
- DBT_DEVICEQUERYREMOVE. Request permission that a device or removable media want. You can refuse a request to remove the device or media. If your application is accessing data in a file that is located in the flash disk and flash disk does not allow it unplugged, you can cancel the request by returning the value BROADCAST_DENY_REQUEST. If agreed to release the flash disk, the contents of the return value to TRUE.
- DBT_DEVICEQUERYREMOVEFAILED. Device or removable media fails.