For Win32 API
ctrlTree.Create(WS_CHILD|TVS_HASBUTTONS|TVS_CHECKBOX|, ctrlRect, this, IDC_TREECTRL);
Then check notification of NM_CLICK event
case NM_CLICK:
{
POINT cursorPos; GetCursorPos(&cursorPos);
ScreenToClient(hwndTree, &cursorPos);
TVHITTESTINFO thinf;
thinf.pt = cursorPos;
TreeView_HitTest(hwndTree, &thinf);
if (thinf.flags == TVHT_ONITEMSTATEICON)
{
BOOL isChecked = TreeView_GetCheckState(hwndTree, thinf.hItem);
if (isChecked)
else
}
}
break;
For MFC
At form designer selectenable the "Check boxes" style on your control.
Then use the following code:
DWORD dwLong = m_tree.GetWindowLong(GWL_EXSTYLE);
dwLong |= TVS_CHECKBOXES;
m_tree.SetWindowLong(GWL_EXSTYLE, dwLong);