vc 获取U盘盘符

[cpp]  view plain  copy
  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. }     


 

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

===========================================================================================

[cpp]  view plain  copy
  1. 映射消息响应函数  
  2. ON_WM_DEVICECHANGE(OnDeviceChange)  
  3.   
  4. 加入  
  5. afx_msg void OnDeviceChange(UINT nEventType, DWORD dwData);  
  6.   
  7.   
  8. void CGggfDlg::OnDeviceChange(UINT nEventType, DWORD dwData)  
  9. {  
  10.     if( nEventType ==32768)   
  11.     {  
  12.         MessageBox(_T("U盘插入"));  
  13.     }  
  14.   
  15.     else if(nEventType ==32772)    
  16.     {  
  17.         MessageBox(_T("U盘拔出"));  
  18.     }  
  19. }  
  20.   
  21.   
  22. ----------------------------------------------------------------------------------------------------------------------------  
  23.   
  24. 获取U盘符  
  25.   
  26.     CString str = _T("z:\\");  
  27.     forchar ch = 'z'; ch >='c'; ch--)  
  28.     {  
  29.         str.SetAt(0,ch);  
  30.         UINT type = GetDriveType(str);  
  31.         if(DRIVE_REMOVABLE == type)  
  32.         {  
  33.             AfxMessageBox(str);  
  34.         }  
  35.     }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值