植发?1、添加 CTreeCtrl 单击响应事件,设置checkbox 的选中状态
void CTestTreeDlg::OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CPoint pt;
GetCursorPos(&pt);
m_Tree_ctlDemo.ScreenToClient(&pt);
UINT nFlag = 0;
HTREEITEM hItem = m_Tree_ctlDemo.HitTest(pt, &nFlag);
if( NULL != hItem )
{
m_Tree_ctlDemo.SelectItem(hItem);
}
*pResult = 0;
}
2、遍历获取checkbox 选中的所有子节点
void CTestTreeDlg::OnOK()
{
CString str;
HTREEITEM htm;
HTREEITEM parentHtm;
HTREEITEM childHtm;
htm = m_Tree_ctlDemo.GetSelectedItem();
if (htm == NULL) return;
//获取当前选中节点的父节点
parentHtm = m_Tree_ctlDemo.GetParentItem(htm);
//获取当前选中节点的子节点
childHtm = m_Tree_ctlDemo.GetChildItem(htm);
if(parentHtm == NULL && childHtm != NULL)
{
return;
}
// 遍历所有子节点
if (m_Tree_ctlDemo.ItemHasChildren(parentHtm))
{
HTREEITEM hItem = m_Tree_ctlDemo.GetChildItem(parentHtm);
if(m_Tree_ctlDemo.GetCheck(hItem)) //判断子节点是否选中
{
str += m_Tree_ctlDemo.GetItemText(hItem) + "\r\n";
}
while (hItem != NULL)
{
m_Tree_ctlDemo.SetItemState(hItem, TVIS_BOLD, TVIS_BOLD);
hItem = m_Tree_ctlDemo.GetNextSiblingItem(hItem);
if(hItem != NULL && m_Tree_ctlDemo.GetCheck(hItem))
{
str += m_Tree_ctlDemo.GetItemText(hItem) + "\r\n";
}
}
}
AfxMessageBox(str);
}
VC++ CTreeCtrl 中 checkbox 的使用
原文:https://www.cnblogs.com/yonghe/p/14517108.html