1、释放节点及所有子节点数据(T表示节点存储的数据类型)
template<typename T> void FreeAllItemsData(_In_ HTREEITEM hItem) { if (hItem == NULL) return; T* pData = (T*)m_Tree.GetItemData(hItem); if (pData) { delete pData; pData = NULL; } HTREEITEM hChild = m_Tree.GetChildItem(hItem); FreeAllItemsData<T>(hChild); HTREEITEM hNextSibling = m_Tree.GetNextSiblingItem(hItem); FreeAllItemsData<T>(hNextSibling); }2、释放节点及所有子节点
void DeleteAllItems(_In_ HTREEITEM hItem) { if (hItem == NULL) return; HTREEITEM hChild = m_Tree.GetChildItem(hItem); DeleteAllItems(hChild); HTREEITEM hNextSibling = m_Tree.GetNextSiblingItem(hItem); DeleteAllItems(hNextSibling); m_Tree.DeleteItem(hItem); }