Windows detects USB drive insert, unplug

Source: Internet
Author: User

Detects the insert or unplug status of the USB drive and then makes relevant actions based on the status.

Detects if the USB stick is plugged in by listening for wm_devicechange messages.

Determine the U-disk pull-out and insert-Get it drive letter .- to-Geneva Ten: -Join Message On_wm_devicechange (ondevicechange) join afx_msgvoidOndevicechange (UINT neventtype, DWORD dwdata);--------------------------------------------------------------------------------------------------------------- ------------------voidCgggfdlg::ondevicechange (UINT neventtype, DWORD dwdata) {if(Neventtype = =32768) {MessageBox (_t ("USB Insert"));} Else if(Neventtype = =32772) {MessageBox (_t ("USB stick Pull out"));}}--------------------------------------------------------------------------------------------------------------- -------------get USB drive character CString str= _t ("z://");  for(CharCH ='Z'; CH >='C'; ch--) {str. SetAt (0, CH); UINT type=GetDriveType (str); if(Drive_removable = =type)        {AfxMessageBox (str); }    }
View Code

Validity has not been validated yet.
Reference Blog: 1,http://blog.csdn.net/veryhehe2011/article/details/7789418

2,http://blog.csdn.net/waveyang/article/details/6260218

Windows detects USB drive insert, unplug

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.