static BOOL FillDriveList() { DRIVE_INFO di; TCHAR chDrive = TEXT('A'); DWORD dwDrives = GetLogicalDrives(); // This failing is not fatal to this function // Make sure the partition table is up to date afs_status_t nStatus; int nResult = ReadPartitionTable(&nStatus); ASSERT(nResult); while (dwDrives) { if (dwDrives & 1) { memset(&di, 0, sizeof(di)); if (GetDriveInfo(chDrive, di)) { FASTLISTADDITEM ai = { 0, di.nImage, IMAGE_NOIMAGE, di.szRootDir, di.bDisabled, di.dwFlags }; HLISTITEM hItem = FastList_AddItem(m_hDriveList, &ai); FastList_SetItemText(m_hDriveList, hItem, 1, di.szVolName); FastList_SetItemText(m_hDriveList, hItem, 2, di.szSize); } } chDrive++; dwDrives >>= 1; } return TRUE; }
//获取当前光驱盘符 CString VirtualDrive::GetDriveName(void) { CString strInfo=GetDriveInfo(); if (strInfo!=L"") { return strInfo.Mid(strInfo.Find(L"[",0)+1,1)+L":"; } else return L""; }
BOOL DrivesTabProc( IN HWND hWnd, IN UINT message, IN WPARAM wParam, IN LPARAM lParam ) /*++ Routine Description: DrivesTabProc processes messages when the Drives Tab is currently selected. Arguments: Standard WINPROC entry. Return Value: BOOL - Depending on input message and processing options. --*/ { BOOL Success; HWND hTreeView; switch( message ) { case WM_INITDIALOG: InitializeDrivesTab(hWnd); break; case WM_DESTROY: FreeDriveInfoStructures( hWnd ); break; case WM_NOTIFY: { switch( ((LPNMHDR)lParam)->code ){ case TVN_GETDISPINFO: { // TVN_GETDISPINFO is sent my I_IMAGECALLBACK to determine // folder state if ((((TV_DISPINFO *)lParam)->item.state) & TVIS_EXPANDED) { ((TV_DISPINFO *)lParam)->item.iImage = ((TV_DISPINFO *)lParam)->item.iSelectedImage = IMAGE_FOLDER_OPEN; } else { ((TV_DISPINFO *)lParam)->item.iImage = ((TV_DISPINFO *)lParam)->item.iSelectedImage = IMAGE_FOLDER_CLOSED; } break; } case TVN_SELCHANGED: { // // Enable or disable the Properties button, depending on whether // this item has any children--only allow properties for items // with no children // TV_ITEM tvi; tvi = ((LPNM_TREEVIEW)lParam)->itemNew; tvi.mask = TVIF_CHILDREN; TreeView_GetItem (GetDlgItem(hWnd, IDC_TV_DRIVE_LIST), &tvi); Success = EnableControl( GetParent(hWnd), IDC_PUSH_PROPERTIES, (tvi.cChildren == 0) ? TRUE : FALSE ); break; } case NM_DBLCLK: { // pretend we have clicked the Property button PostMessage( GetParent(hWnd), WM_COMMAND, MAKEWPARAM( IDC_PUSH_PROPERTIES, BN_CLICKED ), 0 ); break; } } } case WM_COMMAND: { LPDRIVE_INFO DriveInfo; switch( LOWORD( wParam )) { case IDC_PUSH_DRIVE_TYPE: case IDC_PUSH_DRIVE_LETTER: case IDC_PUSH_REFRESH: FreeDriveInfoStructures( hWnd ); FillTreeViewWithDrives( hWnd, GetDlgItem(hWnd, IDC_TV_DRIVE_LIST), LOWORD( wParam ) ); EnableControl( GetParent(hWnd), IDC_PUSH_PROPERTIES, FALSE); break; case IDC_PUSH_SCSI_CHAIN: DisplaySCSIDevices( hWnd, GetDlgItem(hWnd, IDC_TV_DRIVE_LIST) ); break; case IDC_PUSH_PHYSICAL_DISKS: //WORKITEM break; case IDC_PUSH_PROPERTIES: if (HIWORD( wParam) == BN_CLICKED) { TV_ITEM tvi; TCHAR szBuffer[512]; tvi.mask = TVIF_TEXT | TVIF_CHILDREN | TVIF_PARAM; tvi.hItem = TreeView_GetSelection( GetDlgItem(hWnd, IDC_TV_DRIVE_LIST) ); tvi.pszText = szBuffer; tvi.cchTextMax = sizeof(szBuffer); TreeView_GetItem (GetDlgItem(hWnd, IDC_TV_DRIVE_LIST), &tvi); if ( !tvi.cChildren ) { if ( GetDriveInfo( (LPDRIVE_INFO) tvi.lParam ) ) { DisplayDrivePropertySheet( hWnd, (LPDRIVE_INFO) tvi.lParam); } else { TCHAR Buffer[256]; wsprintf( Buffer, (LPCTSTR) GetString( IDS_APPLICATION_FULLNAME )); MessageBox ( hWnd, (LPCTSTR) GetString( IDS_DRIVE_PROPERTY_NOT_AVAILABLE ), Buffer, MB_ICONSTOP | MB_OK ); } } break; } } break; } } return(FALSE); }
BOOL BuildDrivesReport( IN HWND hWnd, IN UINT iDetailLevel ) /*++ Routine Description: Formats and adds DrivesData to the report buffer. Arguments: hWnd - Main window handle iDetailLevel - summary or complete details? Return Value: BOOL - TRUE if report is build successfully, FALSE otherwise. --*/ { TCHAR LogicalDrives[ MAX_PATH ], OutputBuffer[MAX_PATH], szBuffer[MAX_PATH], szBuffer2[MAX_PATH]; LPTSTR Drive; DWORD Chars; BOOL Success; UINT OldErrorMode; DRIVE_INFO di; LARGE_INTEGER LargeInt; TCHAR szTotalBytes [ 64 ], szFreeBytes [ 64 ]; if(_fIsRemote){ return(TRUE); } AddLineToReport( 1, RFO_SKIPLINE, NULL, NULL ); AddLineToReport( 0, RFO_SINGLELINE, (LPTSTR) GetString( IDS_DRIVES_REPORT ), NULL ); AddLineToReport( 0, RFO_SEPARATOR, NULL, NULL ); // // Retrieve the logical drive strings from the system. // Chars = GetLogicalDriveStrings( sizeof( LogicalDrives ), LogicalDrives ); DbgAssert(( Chars != 0 ) && ( Chars <= sizeof( LogicalDrives ))); Drive = LogicalDrives; // // Disable pop-ups (especially if there is no media in the // removable drives.) // OldErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS ); while( *Drive ) { TCHAR VolumeNameBuffer[512]; TCHAR FileSystemNameBuffer[512]; TCHAR DriveLetter[3]; TCHAR szKB[64]; DriveLetter[ 0 ] = Drive [ 0 ]; DriveLetter[ 1 ] = Drive [ 1 ]; DriveLetter[ 2 ] = TEXT( '\\'); ZeroMemory( &di, sizeof(DRIVE_INFO)); // // Skip floppies // if ((Drive[0] == 'A') || (Drive[0] == 'B')) { Drive += _tcslen( Drive ) + 1; continue; } // // GetDrive info // _tcsncpy( di.DriveLetter, Drive, 4 ); GetDriveInfo( &di ); // // Skip empty drives // if (di.Clusters == 0) { Drive += _tcslen( Drive ) + 1; continue; } // // skip unknown types // if (( di.DriveType < DRIVE_REMOVABLE) || ( di.DriveType > DRIVE_CDROM )){ Drive += _tcslen( Drive ) + 1; continue; } // // Display summary information // lstrcpy(szBuffer, GetString( IDS_DRV_BASE + di.DriveType ) ); lstrcpy(szBuffer2, GetString( IDS_TOTAL_MB ) ); // // Calculate the total and free bytes (Use LargeInteger routines for large drives ( > 4G ) // LargeInt.QuadPart = UInt32x32To64( di.FreeClusters, (di.SectorsPerCluster * di.BytesPerSector) ); LargeInt.QuadPart = Int64ShraMod32(LargeInt.QuadPart, 10); lstrcpy( szFreeBytes, FormatLargeInteger( &LargeInt, FALSE )); LargeInt.QuadPart = UInt32x32To64( di.Clusters, (di.SectorsPerCluster * di.BytesPerSector) ); LargeInt.QuadPart = Int64ShraMod32(LargeInt.QuadPart, 10); lstrcpy( szTotalBytes, FormatLargeInteger( &LargeInt, FALSE )); lstrcpy( szKB, GetString( IDS_KB ) ); if (di.DriveType == DRIVE_REMOTE) { wsprintf(OutputBuffer, L"%.2s (%s - %s) %s %s %s %s %s, %s %s %s", di.DriveLetter, szBuffer, di.FileSystemNameBuffer, di.RemoteNameBuffer, di.VolumeNameBuffer, szBuffer2, szTotalBytes, szKB, GetString( IDS_FREE_MB ), szFreeBytes, szKB); AddLineToReport(0,RFO_SINGLELINE,OutputBuffer,NULL); } else { wsprintf(OutputBuffer, L"%s (%s - %s) %s %s %s %s, %s %s %s", di.DriveLetter, szBuffer, di.FileSystemNameBuffer, di.VolumeNameBuffer, szBuffer2, szTotalBytes, szKB, GetString( IDS_FREE_MB ), szFreeBytes, szKB); AddLineToReport(0,RFO_SINGLELINE,OutputBuffer,NULL); } // // If we are making a detailed report, display additional info // if (iDetailLevel == IDC_COMPLETE_REPORT) { wsprintf( szBuffer, L"%X - %X", HIWORD( di.VolumeSerialNumber ), LOWORD( di.VolumeSerialNumber )); AddLineToReport( SINGLE_INDENT, RFO_RPTLINE, (LPTSTR) GetString( IDS_DRIVE_SERIAL_NUM ), szBuffer ); wsprintf(szBuffer, L"%d", di.BytesPerSector); AddLineToReport( SINGLE_INDENT, RFO_RPTLINE, (LPTSTR) GetString( IDS_BYTES_PER_CLUSTER ), szBuffer ); wsprintf(szBuffer, L"%d", di.SectorsPerCluster); AddLineToReport( SINGLE_INDENT, RFO_RPTLINE, (LPTSTR) GetString( IDS_SECTORS_PER_CLUSTER ), szBuffer ); wsprintf(szBuffer, L"%d", di.MaximumComponentLength); AddLineToReport( SINGLE_INDENT, RFO_RPTLINE, (LPTSTR) GetString( IDS_CHARS_IN_FILENAME ), szBuffer ); } // // Examine the next logical drive. // Drive += _tcslen( Drive ) + 1; } // // Restore error mode // SetErrorMode (OldErrorMode); return TRUE; }