想做一个文件列表树,把驱动器里所有的文件都用树显示出来,请各位大虾指教!

解决方案 »

  1.   

    FindFirstFile,FindNextFile,然后递归
      

  2.   


    BOOL CMyControlDlg::OnInitDialog() 

     // TODO: Add extra initialization here 
     /*初始化*/ 
     //图标数组 
     HICON hIcon[4]; 
     hIcon[0]=AfxGetApp()->LoadIcon(IDI_CLOSE); 
     hIcon[1]=AfxGetApp()->LoadIcon(IDI_OPEN); 
     hIcon[2]=AfxGetApp()->LoadIcon(IDI_DRIVE); 
     hIcon[3]=AfxGetApp()->LoadIcon(IDI_FILE);  //图标列表 
     m_imagelist.Create(16, 16, ILC_COLOR32| ILC_MASK, 4, 4); 
     m_imagelist.Add(hIcon[0]); 
     m_imagelist.Add(hIcon[1]); 
     m_imagelist.Add(hIcon[2]); 
     m_imagelist.Add(hIcon[3]);  //控件指针 
     CTreeCtrl * pTreeCtrl=(CTreeCtrl *)GetDlgItem(IDC_TREE1); 
     pTreeCtrl->SetImageList(&m_imagelist,TVSIL_NORMAL);  //树结点 
     HTREEITEM hRoot; 
     hRoot=pTreeCtrl->InsertItem(_T("D:"),2,2,NULL);  //递归遍历目录 
     BrowseDir( "d:",  hRoot);  return TRUE;  // return TRUE  unless you set the focus to a control 
    } void CMyControlDlg::BrowseDir( CString strDir ,HTREEITEM hParent ) 

     CFileFind fileFind; 
     CString szDir = strDir; 
     HTREEITEM hChild; 
     CTreeCtrl * pTreeCtrl=(CTreeCtrl *)GetDlgItem(IDC_TREE1);   if(szDir.Right(1) != "\\") 
     { 
       szDir += "\\"; 
     } 
     szDir += "*.*"; 
     BOOL res = fileFind.FindFile(szDir);  while( res ) 
     {    res = fileFind.FindNextFile();    if(fileFind.IsDirectory() && !fileFind.IsDots()) 
       { 
         CString strPath = fileFind.GetFilePath(); 
         CString strFileName = fileFind.GetFileName(); 
         hChild = pTreeCtrl->InsertItem(strFileName,0,0,hParent); 
         BrowseDir( strPath, hChild ); 
       } 
       else if(!fileFind.IsDirectory() && !fileFind.IsDots()) 
       { 
         CString strFileName = fileFind.GetFileName(); 
         pTreeCtrl->InsertItem(strFileName,3,3,hParent); 
       } 

       fileFind.Close(); 
    } Lz可以参考一下
    不要一copy就完事了哦
      

  3.   

    谢谢,我找到一个开源的IEShell。但是还是非常感谢你的回答!