1. Add a message
Message ing
Begin_message_map (caft_1394dlg, cdialog)
// {Afx_msg_map (caft_1394dlg)
On_wm_paint ()
On_wm_querydragicon ()
...
On_wm_devicechange ()
//} Afx_msg_map
Voice
Message response function:
Afx_msg bool ondevicechange (uint neventtype, DWORD dwdata );
Set
Function content:
Bool xxxxxxx: ondevicechange (uint neventtype, DWORD
Dwdata)
{
Dev_broadcast_deviceinterface * DBD =
(Dev_broadcast_deviceinterface *) dwdata;
// Information matching, such as guid
//
Process events.
Switch (neventtype)
{
Case
Dbt_deviceremovecomplete:
...
Break;
Case
Dbt_devicearrival:
...
Break;
...
...
...
Default:
Break;
}
Return true;
}
2. register the device
If
(Handle
= NULL)
Return false;
Dev_broadcast_deviceinterface
Devint;
Memset (& devint, 0, sizeof (dev_broadcast_deviceinterface ));
Devint. dbcc_size
= Sizeof (dev_broadcast_deviceinterface );
Devint. dbcc_devicetype =
Dbt_devtyp_deviceinterface;
Devint. dbcc_classguid =
Getcurrentusbguid (); // m_usb-> getdriverguid ();
If
(! Registerdevicenotification (m_hwnd,
& Devint, device_policy_window_handle ))
Return false;
Only
If you have registered the device, ondevicechange can obtain detailed information. Otherwise, all received parameters are 0007.