转载http://www.cnblogs.com/lujin49/p/4573616.html
对进行了修改
void CTestTimerDlg::SetParentCheck(HTREEITEM hTree,BOOL bCheck)
{
HTREEITEM hParent = m_TreeCtrl.GetParentItem(hTree);
if (hParent)
{
HTREEITEM hChild = m_TreeCtrl.GetChildItem(hParent);
while (hChild)
{
if (hChild == hTree)
{
hChild = m_TreeCtrl.GetNextSiblingItem(hChild);
continue;
}
BOOL bflag = m_TreeCtrl.GetCheck(hChild);
if (bCheck == bflag) //判断是否还有兄弟项被选择
{
if(bCheck == FALSE)
return;
}
hChild = m_TreeCtrl.GetNextSiblingItem(hChild);
}
m_TreeCtrl.SetCheck(hParent,!bCheck);
SetParentCheck(hParent,bCheck); //设置父项的状态
}