Take the dialog box project as an example
Header file
Afx_msg bool ondevicechange (uint neventtype, DWORD dwdata );
CPP
On_wm_devicechange ()
Then implement the function
Bool cxxdlg: ondevicechange (uint neventtype, DWORD dwdata) {// 0x4d36e978l, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 // dev_broadcast_deviceinterface * DBD = (dev_broadcast_deviceinterface *) dwdata; dev_broadcast_hdr * DHR = (dev_broadcast_hdr *) dwdata; trace ("-- neventtype --: % d \ n ", neventtype); Switch (neventtype) {Case dbt_deviceremovecomplete: // remove the device trace (" -- device remove -- \ n "); # If 1if (DHR-> dbch_devicetype = dbt_devtyp_port) {pdev_broadcast_port lpdbv = (pdev_broadcast_port) DHR; int Len = strlen (lpdbv-> dbcp_name ); cstring name (lpdbv-> dbcp_name); // com8int Port = 0; sscanf (name. getbuffer (0), "Com % d", & Port) ;}# endiftrace ("-- device remove -- end \ n"); break; Case dbt_devicearrival: // Add the device trace ("-- device arrival -- \ n"); # If 1if (DHR-> dbch_devicetype = dbt_devtyp_port) {pdev_broadcast_port lpdbv = (pdev_broadcast_port) DHR; int Len = strlen (lpdbv-> dbcp_name); cstring name (lpdbv-> dbcp_name); // com8int Port = 0; sscanf (name. getbuffer (0), "Com % d", & Port) ;}# endifbreak; default: break;} return true ;}