获取MFC树控件所有节点附加数据


void GetAllItemData(const CTreeCtrl& tree, HTREEITEM hItem, map& itmData)
{ 
    if (NULL == hItem)
    {
        return ;
    }
    
    itmData.insert(make_pair(hItem,tree.GetItemData(hItem)));

    HTREEITEM hChildItem =  tree.GetChildItem(hItem);
    if (NULL != hChildItem)
    {
        GetAllItemData(tree, hChildItem, itmData);
    }

    HTREEITEM hSib = tree.GetNextSiblingItem(hItem);
    if (hSib != NULL)
    {
        GetAllItemData(tree, hSib, itmData);
    }
}

调用方法:

    map itmData;
    GetAllItemData(m_tree, m_tree.GetRootItem(), itmData);