参考MSDN例子:Detecting Media Insertion or Removal
响应WM_DEVICECHANGE 消息:
BOOL OnDeviceChange( UINT nEventType, DWORD dwData )
{
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)dwData; // struct transform
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;switch (nEventType)
{
case DBT_DEVNODES_CHANGED:
...break;
case DBT_DEVICEARRIVAL: // device arrival
if(GetDriveType(UDriveName)==DRIVE_REMOVABLE)
{........
}
else
{......
}
break;
case DBT_DEVICEREMOVECOMPLETE : // remove device
........
break;}
return TRUE;
}