winAPI 检查系统设备拔插使用 WM_DEVICECHANGE 消息

if(message->message == WM_DEVICECHANGE)
{
/*if (message->wParam == DBT_DEVICEARRIVAL || message->wParam == DBT_DEVICEREMOVECOMPLETE)
{
PDEV_BROADCAST_HDR pHeader = (PDEV_BROADCAST_HDR)message->lParam;
if (pHeader->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{
hotplug_onSystemDeviceChanged();
}
}*/
//DBT_DEVNODES_CHANGED:: The system broadcasts the DBT_DEVNODES_CHANGED device event when a device has been added to or removed from the system.
//Applications that maintain lists of devices in the system should refresh their lists.
if (message->wParam == DBT_DEVNODES_CHANGED && message->lParam == 0)
{
hotplug_onSystemDeviceChanged();
}
}

原文地址:https://www.cnblogs.com/hqu-ye/p/4832281.html