小弟今日编写程序过程中预碰见的问题,我想把某个文件夹下面的所有文件夹和子文件夹全部列到一个TreeCtrl里面,但是本人算法没学好,现在不知道怎幺编写.
希望大家帮忙.

解决方案 »

  1.   

    void CSelectDirectory::FillSubDirToTreeCtrl(HTREEITEM *pItem)
    {
    WIN32_FIND_DATA nFind; //--m_DeepNess;
    HTREEITEM nSubItem;
    TCHAR nCurDirectory[ MAX_PATH ];
    GetCurrentDirectory( MAX_PATH, nCurDirectory );

    CString strDirectory;
    if ( nCurDirectory[ strlen( nCurDirectory ) - 1 ] != '\\' )
    strcat( nCurDirectory, "\\" );

    HANDLE nHandle = ::FindFirstFile( "*.*", &nFind );

    do
    {
    if ( ( nFind.dwFileAttributes & ATTRIB_SUBDIR ) && ( nFind.cFileName[ 0 ] != '.' ) )
    {
    nSubItem = m_Directory.InsertItem( nFind.cFileName, 1, 0, *pItem, TVI_LAST );
    // if ( m_DeepNess )
    // {
    strDirectory = nCurDirectory;
    strDirectory += nFind.cFileName;
    SetCurrentDirectory( strDirectory );
    FillSubDirToTreeCtrl( &nSubItem );
    //}
    }
    }
    while( ::FindNextFile( nHandle, &nFind ) );
    //m_DeepNess ++;
    }用递归,试试吧。
      

  2.   

    还有,第一次使用了FindFirstFile之后,就已经找到了第一个文件了吗
      

  3.   

    HTREEITEM nItem = TVI_ROOT;
    m_Directory.DeleteAllItems();
    FillSubDirToTreeCtrl( &nItem );
    就这样用就行了,试试!
      

  4.   

    FindFirstFile就找到了第一个文件。