Add the wm_devicechange message function to VC ++.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.