BOOL CDirTreeCtrl::DisplayDrives() { // // Displaying the Availible Drives on this PC // This are the First Items in the TreeCtrl // DeleteAllItems(); TCHAR szDrives[128]; TCHAR* pDrive; if ( !GetLogicalDriveStrings( sizeof(szDrives), szDrives ) ) { m_strError = "Error Getting Logical DriveStrings!"; return FALSE; } pDrive = szDrives; while( *pDrive ) { HTREEITEM hParent = AddItem( TVI_ROOT, pDrive ); if(_tcsicmp(pDrive,_T("A:\\"))!=0) { if ( FindSubDir( pDrive ) ) InsertItem( _T(""), 0, 0, hParent ); } pDrive += _tcslen( pDrive ) + 1; } return TRUE; }
BOOL CDirTreeCtrl::DisplayDrives() { DeleteAllItems(); TCHAR szDrives[260]; TCHAR* pDrive=NULL; if ( !GetLogicalDriveStrings( sizeof(szDrives), szDrives ) ) { m_strError =_T("驱动信息获取失败!"); return FALSE; } pDrive = szDrives; //szDrives 中的字符串格式:_T("C:\\0D:\\0D:\\0E:\\0") m_hDirTreeRoot = InsertItem(_T("project")); int len; while( *pDrive!=0 ) { len = _tcslen(pDrive); pDrive[len-1] = _T('\0'); HTREEITEM hParent = AddItem( m_hDirTreeRoot, pDrive ); if ( FindSubDir( pDrive )) AddSubDirAsItem(hParent); pDrive += len + 1; } Expand( m_hDirTreeRoot, TVE_EXPAND ); return TRUE; }
BOOL CDirTreeCtrl::DisplayDrives() { // // Displaying the Availible Drives on this PC // This are the First Items in the TreeCtrl // DeleteAllItems(); char szDrives[128]; char* pDrive; if ( !GetLogicalDriveStrings( sizeof(szDrives), szDrives ) ) { m_strError = "Error Getting Logical DriveStrings!"; return FALSE; } pDrive = szDrives; while( *pDrive ) { if (!m_bFixedOnly || GetDriveType(pDrive) == DRIVE_FIXED) { *pDrive = toupper(*pDrive); HTREEITEM hParent = AddItem( TVI_ROOT, pDrive ); if ( FindSubDir( pDrive ) ) InsertItem( "", 0, 0, hParent ); } pDrive += strlen( pDrive ) + 1; } return TRUE; }
void CDirTreeCtrl::DisplayPath(HTREEITEM hParent, LPCTSTR strPath) { // // Displaying the Path in the TreeCtrl // CFileFind find; CString strPathFiles = strPath; BOOL bFind; CSortStringArray strDirArray; CSortStringArray strFileArray; if ( strPathFiles.Right(1) != _T("\\") ) strPathFiles += _T("\\"); strPathFiles += _T("*.*"); bFind = find.FindFile( strPathFiles ); while ( bFind ) { bFind = find.FindNextFile(); if ( find.IsDirectory() && !find.IsDots() ) { strDirArray.Add( find.GetFilePath() ); } if ( !find.IsDirectory() && m_bFiles ) strFileArray.Add( find.GetFilePath() ); } strDirArray.Sort(); SetRedraw( FALSE ); CWaitCursor wait; for ( int i = 0; i < strDirArray.GetSize(); i++ ) { HTREEITEM hItem = AddItem( hParent, strDirArray.GetAt(i) ); if ( FindSubDir( strDirArray.GetAt(i) ) ) InsertItem( _T(""), 0, 0, hItem ); } if ( m_bFiles ) { strFileArray.Sort(); for (int i = 0; i < strFileArray.GetSize(); i++ ) { HTREEITEM hItem = AddItem( hParent, strFileArray.GetAt(i) ); } } SetRedraw( TRUE ); }
BOOL CDirTreeCtrl::AddSubDirAsItem(HTREEITEM hParent) { CString strPath,strFileName; HTREEITEM hChild; //---------------------去除该父项下所有的子项------------ // 因为有dummy项,并且有时子目录再次打开,或子目录会刷新等,因此必须去除。 while ( ItemHasChildren(hParent)) { hChild = GetChildItem(hParent); DeleteItem( hChild ); } //-----------------------装入该父项下所有子项-------------- strPath = GetFullPath(hParent); // 从本节点开始到根的路径 CString strSearchCmd = strPath; if( strSearchCmd.Right( 1 ) != _T( "\\" )) strSearchCmd += _T( "\\" ); strSearchCmd += _T( "*.*" ); CFileFind find; BOOL bContinue = find.FindFile( strSearchCmd ); while ( bContinue ) { bContinue = find.FindNextFile(); strFileName = find.GetFileName(); if ( !find.IsHidden() && ! find.IsDots() && find.IsDirectory() ) { hChild = AddItem( hParent, strFileName ); if ( FindSubDir( GetFullPath(hChild) )) AddSubDirAsItem1(hChild); } if ( !find.IsHidden() && ! find.IsDots() && !find.IsDirectory() ) { InsertItem( strFileName, 0, 0, hParent ); } } return TRUE; }