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