你在监听这个WM_DEVICECHANGE事件的类型号为DBT_DEVICEREMOVECOMPLETE(拔出设备时),
它的lParam的解释如下:
lParam
Pointer to a structure identifying the device removed. The structure consists of an event-independent header, followed by event-dependent members that describe the device. To use this structure, treat the structure as a DEV_BROADCAST_HDR structure, then check its dbch_devicetype member to determine the device type.
重要的是最后一句,也就是DEV_BROADCAST_HDR的第二个参数dbch_devicetype,你再去看下这个里面,应该可以得到启示了
这个参数的值可以为DBT_DEVTYP_PORT这个结构体,再跟下去看下,第四个参数(设备名称)
dbcp_name
Pointer to a null-terminated string specifying the friendly name of the port or the device connected to the port. Friendly names are intended to help the user quickly and accurately identify the device—for example, "COM1" and "Standard 28800 bps Modem" are considered friendly names.
switch(Event) {
case DBT_CONFIGCHANGECANCELED:
strMes = "A request to change the current configuration (dock or undock) has been canceled. ";
break;
case DBT_CONFIGCHANGED:
strMes = "The current configuration has changed, due to a dock or undock.";
break;
case DBT_DEVICEARRIVAL:
strMes = "A device has been inserted and is now available. " ;
strMes += "\n";
switch(pHDR->dbch_devicetype) {
case DBT_DEVTYP_OEM :
strMes += "OEM- or IHV-defined device type. ";
break;
case DBT_DEVTYP_VOLUME:
strMes += " Logical volume. ";
break;
case DBT_DEVTYP_PORT:
strMes += " Port device (serial or parallel). ";
break;
default:
break;
}
break;
case DBT_DEVICEQUERYREMOVE :
strMes = "Permission is requested to remove a device. Any application can deny this request and cancel the removal. ";
break;
case DBT_DEVICEQUERYREMOVEFAILED:
strMes = "A request to remove a device has been canceled. ";
break;
case DBT_DEVICEREMOVECOMPLETE:
strMes = "A device has been removed. ";
break;
case DBT_DEVICEREMOVEPENDING:
strMes = "A device is about to be removed. Cannot be denied. ";
break;
case DBT_DEVICETYPESPECIFIC:
strMes = "A device-specific event has occurred. ";
break;
case DBT_QUERYCHANGECONFIG:
strMes = "Permission is requested to change the current configuration (dock or undock). ";
break;
case DBT_USERDEFINED:
strMes ="The meaning of this message is user-defined. ";
break;
default:
break;