Static const GUID GUID_DEVINTERFACE_LIST []={0 xeb781aaf, 0 x9c70, 0 x4523, {x64 xa5 0, 0 XDF, 0, 0 x2a, 0 x87, 0 xec, 0 xa5, 0 x67}};
Registered under the Mainframe OnCreate
HDEVNOTIFY HDEVNOTIFY;
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
ZeroMemory (& amp; NotificationFilter, sizeof (NotificationFilter));
NotificationFilter. Dbcc_size=sizeof (DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter. Dbcc_devicetype=DBT_DEVTYP_DEVICEINTERFACE;
for(int i=0; i{
NotificationFilter. Dbcc_classguid=GUID_DEVINTERFACE_LIST [I];
HDevNotify=RegisterDeviceNotification (this - & gt; GetSafeHwnd (), & amp; NotificationFilter DEVICE_NOTIFY_WINDOW_HANDLE);
if( ! HDevNotify)
{
AfxMessageBox (cstrings (" Can 't register device notification: ")
+ _com_error (GetLastError ()). ErrorMessage (), MB_ICONEXCLAMATION);
Return FALSE;
}
}
Add the WM_DEVICECHANGE response function
LRESULT CMainFrame: : OnMyDeviceChange (WPARAM WPARAM, LPARAM LPARAM)equipment are plug, wParam is 7, could you tell me this is not registered under the USB message
{
If (DBT_DEVICEARRIVAL==wParam | | DBT_DEVICEREMOVECOMPLETE==wParam) {
PDEV_BROADCAST_HDR pHdr=(lParam PDEV_BROADCAST_HDR);
PDEV_BROADCAST_DEVICEINTERFACE pDevInf;
PDEV_BROADCAST_HANDLE pDevHnd;
PDEV_BROADCAST_OEM pDevOem;
PDEV_BROADCAST_PORT pDevPort;
PDEV_BROADCAST_VOLUME pDevVolume;
The switch (pHdr - & gt; Dbch_devicetype) {
Case DBT_DEVTYP_DEVICEINTERFACE:
{
//need operation
}
break;
Case DBT_DEVTYP_HANDLE:
PDevHnd=(PDEV_BROADCAST_HANDLE pHdr);
break;
Case DBT_DEVTYP_OEM:
PDevOem=(PDEV_BROADCAST_OEM pHdr);
break;
Case DBT_DEVTYP_PORT:
PDevPort=(PDEV_BROADCAST_PORT pHdr);
break;
Case DBT_DEVTYP_VOLUME:
PDevVolume=(PDEV_BROADCAST_VOLUME pHdr);
break;
}
}
return 0;
}
CodePudding user response:
Sorry didn't have written such hardware detection code, but since when equipment plug, you can see whether wParam is 7 is a response to the news.Only DBT_DEVICEARRIVAL device driver is already installed and available DBT_DEVICEREMOVECOMPLETE removal equipment for processing events, I can't find these macros F12 positioning here... I do not know how much value...
CodePudding user response: