想用CTreeCtrl实现一个浏览FTP服务器路径的功能,不知道用什么方法可以记录下当前选中项的路径,只知道用GetItemText可以获得当前选中项的内容,如果一直连接字符串记录路径的话,比如当前记录的路径为:\ABC\123\QWE,如果此时单击与123同级的目录,就无法记录路径了,请问有什么好办法吗?

解决方案 »

  1.   

    有,读它的父节点GetParentItem,循环一直读
      

  2.   

    方法:得到父节点路径
     CString GetTreePath(HTREEITEM   &hItemSelect,CTreeCtrl   &ctrl)
    {
          CString    strRet;//返回路径
           while(hItemSelect )
           { 
              
               CString   strItemText=ctrl.GetItemText(hItemSelect);//得到本节点的文本
                 strRet    +=strItemText;
                 HTREEITEM   hParentItem=ctrl.GetParentItem(hItemSelect);//得到父节点
               hItemSelect=hParentItem;//替换节点
           } 
         return    strRet;
    }
      

  3.   

    HTREEITEM hRoot;
            CString strFullPath;
            CString strItem;
            HTREEITEM hSelItem = GetSelectedItem();/*得到当前选定节点句柄*/        hRoot = hSelItem; while( (hRoot = GetParentItem(hRoot)) != NULL)
    {
    strItem = GetItemText(hRoot);
                    if(!strFullPath.Empty())
                    strFullPath +="\\";
                    strFullPath += strItem;
    }
            return strFullPath;