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.     }  
發佈了29 篇原創文章 · 獲贊 97 · 訪問量 49萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章