MFC detects serial port plugging

Source: Internet
Author: User

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 ;}


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.