- UINT DiskType;
- size_t szAllDriveStrings = GetLogicalDriveStrings(0,NULL);
- char *pDriveStrings = new char[szAllDriveStrings + sizeof(_T( " "))];
- GetLogicalDriveStrings(szAllDriveStrings,pDriveStrings);
- size_t szDriveString = strlen(pDriveStrings);
- while(szDriveString > 0)
- {
- AfxMessageBox(pDriveStrings);
- DiskType=GetDriveType(pDriveStrings);
- switch(DiskType)
- {
- case DRIVE_NO_ROOT_DIR:
- return;
- case DRIVE_REMOVABLE:
- ::AfxMessageBox( "移动存储设备 ");
- break;
- case DRIVE_FIXED:
- ::AfxMessageBox( "固定硬盘驱动器 ");
- break;
- case DRIVE_REMOTE:
- ::AfxMessageBox( "这是网络驱动器 ");
- break;
- case DRIVE_CDROM:
- ::AfxMessageBox( "这是光盘驱动器 ");
- break;
- }
- pDriveStrings += szDriveString + 1;
- szDriveString = strlen(pDriveStrings);
- }
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
===========================================================================================
- 映射消息响应函数
- ON_WM_DEVICECHANGE(OnDeviceChange)
- 加入
- afx_msg void OnDeviceChange(UINT nEventType, DWORD dwData);
- void CGggfDlg::OnDeviceChange(UINT nEventType, DWORD dwData)
- {
- if( nEventType ==32768)
- {
- MessageBox(_T("U盘插入"));
- }
- else if(nEventType ==32772)
- {
- MessageBox(_T("U盘拔出"));
- }
- }
- ----------------------------------------------------------------------------------------------------------------------------
- 获取U盘符
- CString str = _T("z:\\");
- for( char ch = 'z'; ch >='c'; ch--)
- {
- str.SetAt(0,ch);
- UINT type = GetDriveType(str);
- if(DRIVE_REMOVABLE == type)
- {
- AfxMessageBox(str);
- }
- }