首先为树控件添加NM_CLICK消息,然后在消息响应函数加上下面代码即可
void CDlgFitleFile::OnClickTreeFiletype(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CPoint pt;
UINT uFlag;
BOOL bCheck;
HTREEITEM hSelectedItem;
HTREEITEM hChildrenItem;
HTREEITEM hNextItem;
uFlag = 0;
pt = ::GetMessagePos();
m_treeFileType.ScreenToClient(&pt);
hSelectedItem = m_treeFileType.HitTest(pt, &uFlag);
if (uFlag & TVHT_ONITEMSTATEICON)
{
m_treeFileType.SelectItem(hSelectedItem);
bCheck = m_treeFileType.GetCheck(hSelectedItem);
if (m_treeFileType.ItemHasChildren(hSelectedItem))
{
hChildrenItem = m_treeFileType.GetChildItem(hSelectedItem);
while (hChildrenItem != NULL)
{
if (!bCheck)
m_treeFileType.SetCheck(hChildrenItem, TRUE);
else
m_treeFileType.SetCheck(hChildrenItem, FALSE);
hNextItem = m_treeFileType.GetNextItem(hChildrenItem, TVGN_NEXT);
hChildrenItem = hNextItem;
}
}
}
*pResult = 0;
}