LRESULT CTestUSBDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_DEVICECHANGE) //0x8000,0x8004
{
CString str;
DEV_BROADCAST_HDR* dhr = (DEV_BROADCAST_HDR *)lParam;
switch(wParam)
{
case DBT_CONFIGCHANGECANCELED:
TRACE( "DBT_CONFIGCHANGECANCELED ");
break;
case DBT_CONFIGCHANGED:
TRACE( "DBT_CONFIGCHANGED ");
break;
case DBT_DEVICEQUERYREMOVE:
TRACE( "DBT_DEVICEQUERYREMOVE ");
break;
case DBT_DEVICEQUERYREMOVEFAILED:
TRACE( "DBT_DEVICEQUERYREMOVEFAILED ");
break;
case DBT_DEVICEREMOVEPENDING:
TRACE( "DBT_DEVICEREMOVEPENDING ");
break;
case DBT_DEVICETYPESPECIFIC:
TRACE( "DBT_DEVICETYPESPECIFIC ");
break;
case DBT_QUERYCHANGECONFIG:
TRACE( "DBT_QUERYCHANGECONFIG ");
break;
case DBT_USERDEFINED:
TRACE( "DBT_USERDEFINED ");
break;
case DBT_DEVICEARRIVAL:
if(dhr-> dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)dhr;
if(lpdbv-> dbcv_flags & DBTF_MEDIA)
{
str.Format( "Drive %c 插入 ", FirstDriveFromMask(lpdbv -> dbcv_unitmask));
//AfxMessageBox(str);
}
else
{
char ch = FirstDriveFromMask(lpdbv -> dbcv_unitmask);
str.Format( "%c:\\ ",ch);
}
}
break;
case DBT_DEVICEREMOVECOMPLETE:
if(dhr-> dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)dhr;
if(lpdbv-> dbcv_flags & DBTF_MEDIA)
{
str.Format( "Drive %c 拔除 ",FirstDriveFromMask(lpdbv -> dbcv_unitmask));
}
else
{
str.Format( "Drive %c 拔除 ",FirstDriveFromMask(lpdbv -> dbcv_unitmask));
}
//AfxMessageBox(str);
}
break;
default:
break;
}
}
return CDialog::WindowProc(message, wParam, lParam);
}
{
if(message == WM_DEVICECHANGE) //0x8000,0x8004
{
CString str;
DEV_BROADCAST_HDR* dhr = (DEV_BROADCAST_HDR *)lParam;
switch(wParam)
{
case DBT_CONFIGCHANGECANCELED:
TRACE( "DBT_CONFIGCHANGECANCELED ");
break;
case DBT_CONFIGCHANGED:
TRACE( "DBT_CONFIGCHANGED ");
break;
case DBT_DEVICEQUERYREMOVE:
TRACE( "DBT_DEVICEQUERYREMOVE ");
break;
case DBT_DEVICEQUERYREMOVEFAILED:
TRACE( "DBT_DEVICEQUERYREMOVEFAILED ");
break;
case DBT_DEVICEREMOVEPENDING:
TRACE( "DBT_DEVICEREMOVEPENDING ");
break;
case DBT_DEVICETYPESPECIFIC:
TRACE( "DBT_DEVICETYPESPECIFIC ");
break;
case DBT_QUERYCHANGECONFIG:
TRACE( "DBT_QUERYCHANGECONFIG ");
break;
case DBT_USERDEFINED:
TRACE( "DBT_USERDEFINED ");
break;
case DBT_DEVICEARRIVAL:
if(dhr-> dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)dhr;
if(lpdbv-> dbcv_flags & DBTF_MEDIA)
{
str.Format( "Drive %c 插入 ", FirstDriveFromMask(lpdbv -> dbcv_unitmask));
//AfxMessageBox(str);
}
else
{
char ch = FirstDriveFromMask(lpdbv -> dbcv_unitmask);
str.Format( "%c:\\ ",ch);
}
}
break;
case DBT_DEVICEREMOVECOMPLETE:
if(dhr-> dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)dhr;
if(lpdbv-> dbcv_flags & DBTF_MEDIA)
{
str.Format( "Drive %c 拔除 ",FirstDriveFromMask(lpdbv -> dbcv_unitmask));
}
else
{
str.Format( "Drive %c 拔除 ",FirstDriveFromMask(lpdbv -> dbcv_unitmask));
}
//AfxMessageBox(str);
}
break;
default:
break;
}
}
return CDialog::WindowProc(message, wParam, lParam);
}