This is the best of the most concise code I wrote personally think it's function is to save the tree is selected directory. as follows:
std :: vector <CString> vecPath; // path storage container
CTreeCtrl m_TreeCtrl; // tree control
TVINSERTSTRUCT tvInsert; // attribute of a directory entry
To initialize the above oh.
HTREEITEM m_Tree = m_TreeCtrl.InsertItem(&tvInsert) // 目录项
/ **
* Function: Get the absolute path of the current directory
* Parameters: HTREEITEM type currently selected item
* 返回类型:CString 类型,表示路径
**/
CString GetFullPath(HTREEITEM hCurrent)
{
CString strTemp;
CString strReturn ;
while(hCurrent != m_Tree)
{
strTemp = m_TreeCtrl.GetItemText(hCurrent);
if(strTemp.Right(1) != _T("\\"))
{
strTemp += _T("\\");
}
strReturn = strTemp + strReturn;
hCurrent = m_TreeCtrl.GetParentItem(hCurrent);
}
return strReturn;
}
/ **
* Function: Save the selected item path
* Parameters: HTREEITEM type currently selected item
* Return type: void type
**/
void InsertString(HTREEITEM hItem)
{
CString path = GetFullPath(hItem);
if (!path.IsEmpty())
{
vecPath.push_back(path);
}
}
/ **
* Function: traversing the currently selected directory entry
* Parameters: HTREEITEM type currently selected item
* Return type: void type
**/
void FindTrueInsert(HTREEITEM hItem)
{
BOOL bSelectd = m_TreeCtrl.GetCheck(hItem);
if (bSelectd)
{
InsertString(hItem);
}
else
{
HTREEITEM child = m_TreeCtrl.GetChildItem(hItem);
while (child)
{
FindTrueInsert(child);
child = m_TreeCtrl.GetNextSiblingItem(child);
}
}
}