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

void GetAllItemData(const CTreeCtrl& tree, HTREEITEM hItem, map<HTREEITEM,DWORD_PTR>& 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<HTREEITEM,DWORD_PTR> itmData;
    GetAllItemData(m_tree, m_tree.GetRootItem(), itmData);

 

posted @ 2020-12-16 15:48  快雪  阅读(492)  评论(0编辑  收藏  举报