如何删除CTreeCtrl某节点的所有子节点
1个回答
展开全部
定义一个递归函数,传入一个节点,函数如下:
BOOL DelItem(CTreeCtrl treeCtrl, HTREEITEM hItem)
{
if(!treeCtrl.ItemHasChildren(hItem))
{
return FALSE;
}
HTREEITEM hChild = treeCtrl.GetChildItem(hItem);
do
{
if(treeCtrl.ItemHasChildren(hChild))
{
DelItem(treeCtrl, hChild);
}
else
{
treeCtrl.DeleteItem(hChild);
}
hChild = treeCtrl.GetNextSiblingItem(hChild);
}while(hChild != NULL);
}
BOOL DelItem(CTreeCtrl treeCtrl, HTREEITEM hItem)
{
if(!treeCtrl.ItemHasChildren(hItem))
{
return FALSE;
}
HTREEITEM hChild = treeCtrl.GetChildItem(hItem);
do
{
if(treeCtrl.ItemHasChildren(hChild))
{
DelItem(treeCtrl, hChild);
}
else
{
treeCtrl.DeleteItem(hChild);
}
hChild = treeCtrl.GetNextSiblingItem(hChild);
}while(hChild != NULL);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询