将文件名做为TreeCtrl的节点的Item data来关联。

解决方案 »

  1.   

    谢谢你的回复,CMainFrame中的BrowseFile函数如下 还能回复的具体点吗,谢谢了void CMainFrame::BrowseFile(int CallNum, CString strFile)
    {
    CallNum++;
    CFileFind ff;
    CString szDir = strFile;

    if(szDir.Right(1) != "\\")
    szDir += "\\";

    szDir += "*.*";

    BOOL res = ff.FindFile(szDir);
    while(res)
    {
    res = ff.FindNextFile();
    if(ff.IsDirectory() && !ff.IsDots())
    {
    //如果是一个子目录,用递归继续往深一层找
    CString strPath = ff.GetFilePath();
    CString strTitle = ff.GetFileTitle();
    int i =0;
    switch(CallNum)
    {
    case 1:
    strHTFir =  m_wndTree.InsertItem(strTitle,0,0,NULL);
    break;
    case 2:
    strHTSec =  m_wndTree.InsertItem(strTitle,0,0,strHTFir);
    break;
    default:
    strHtThi =  m_wndTree.InsertItem(strTitle,0,0,strHTSec);
    break;



    }
    BrowseFile(CallNum,strPath);
    }
    else if(!ff.IsDirectory() && !ff.IsDots())
    {
    //显示当前访问的文件
    CString strPath;
    CString strTitle;
    strPath = ff.GetFilePath();
    strTitle = ff.GetFileTitle();
    switch(CallNum)
    {
    case 1:
    strRoot =  m_wndTree.InsertItem(strTitle,0,0,NULL);
    break;
    case 2:
    strHtEnd =  m_wndTree.InsertItem(strTitle,0,0,strHTFir);
    break;
    case 3:
    strHtEnd =  m_wndTree.InsertItem(strTitle,0,0,strHTSec);
    break;
            default:
    strHtEnd =  m_wndTree.InsertItem(strTitle,0,0,strHtThi);
    break;

    }
    }
    }
    ff.Close();//关闭
    }
      

  2.   

    DWORD CTreeCtrl::GetItemData(HTREEITEM hItem) const
    {
    ASSERT(::IsWindow(m_hWnd));
    TVITEM item;
    item.hItem = hItem;
    item.mask = TVIF_PARAM;
    VERIFY(::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item));
    return (DWORD)item.lParam;
    }
    是这个吗 ???望高人指点
      

  3.   

    你在InsertItem之后把文件全路径字符串用SetItemData保存到节点中,以后在点击节点的消息中就可以取出来,传递给视图窗口用于读取。
      

  4.   

    你可以参考http://blog.csdn.net/jiangsheng/archive/2003/11/20/3796.aspx
      

  5.   

    对了,,如果lz有代码,希望lz能解救我