Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1606003
  • 博文数量: 695
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 4027
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-20 21:22
文章分类

全部博文(695)

文章存档

2018年(18)

2017年(74)

2016年(170)

2015年(102)

2014年(276)

2013年(55)

分类: Windows平台

2014-01-09 17:43:56


点击(此处)折叠或打开

  1. UINT DiskType;
  2.  size_t szAllDriveStrings = GetLogicalDriveStrings(0,NULL);
  3. char *pDriveStrings = new char[szAllDriveStrings + sizeof(_T( " "))];
  4. GetLogicalDriveStrings(szAllDriveStrings,pDriveStrings);
  5. size_t szDriveString = strlen(pDriveStrings);
  6. while(szDriveString > 0)
  7. {
  8.   AfxMessageBox(pDriveStrings);
  9.   DiskType=GetDriveType(pDriveStrings);
  10.   switch(DiskType)
  11.   {
  12.   case DRIVE_NO_ROOT_DIR:
  13.    return;
  14.   case DRIVE_REMOVABLE:
  15.    ::AfxMessageBox( "移动存储设备 ");
  16.    break;
  17.   case DRIVE_FIXED:
  18.    ::AfxMessageBox( "固定硬盘驱动器 ");
  19.    break;
  20.   case DRIVE_REMOTE:
  21.    ::AfxMessageBox( "这是网络驱动器 ");
  22.    break;
  23.   case DRIVE_CDROM:
  24.    ::AfxMessageBox( "这是光盘驱动器 ");
  25.    break;
  26.    
  27.   }
  28.   
  29.   pDriveStrings += szDriveString + 1;
  30.   szDriveString = strlen(pDriveStrings);
  31. }


点击(此处)折叠或打开

  1. 映射消息响应函数
  2. ON_WM_DEVICECHANGE(OnDeviceChange)

  3. 加入
  4. afx_msg void OnDeviceChange(UINT nEventType, DWORD dwData);


  5. void CGggfDlg::OnDeviceChange(UINT nEventType, DWORD dwData)
  6. {
  7.     if( nEventType ==32768)
  8.     {
  9.         MessageBox(_T("U盘插入"));
  10.     }

  11.     else if(nEventType ==32772)
  12.     {
  13.         MessageBox(_T("U盘拔出"));
  14.     }
  15. }


  16. ----------------------------------------------------------------------------------------------------------------------------

  17. 获取U盘符

  18.     CString str = _T("z:\\");
  19.     for( char ch = 'z'; ch >='c'; ch--)
  20.     {
  21.         str.SetAt(0,ch);
  22.         UINT type = GetDriveType(str);
  23.         if(DRIVE_REMOVABLE == type)
  24.         {
  25.             AfxMessageBox(str);
  26.         }
  27.     }


阅读(3719) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~