1, 复选框选中或取消选中,会触发什么消息,我看它的消息句柄里没有这样的消息啊
2。 我想动态地设置CTreeCtrl中ITEM的选中状态,
mc_tcTree.Initialize(true);
HTREEITEM hItem= mc_tcTree.GetNext();
CString str ;
while (hItem != NULL)
{
if(mc_tcTree.ItemHasChildren(hItem)==false) {
str = mc_tcTree.GetItemText(hItem) ;
if(str == name) {
mc_tcTree.SetCheck(hItem,true);
return ;
} hItem= mc_tcTree.GetNext();
}
return NULL ;
2。 我想动态地设置CTreeCtrl中ITEM的选中状态,
mc_tcTree.Initialize(true);
HTREEITEM hItem= mc_tcTree.GetNext();
CString str ;
while (hItem != NULL)
{
if(mc_tcTree.ItemHasChildren(hItem)==false) {
str = mc_tcTree.GetItemText(hItem) ;
if(str == name) {
mc_tcTree.SetCheck(hItem,true);
return ;
} hItem= mc_tcTree.GetNext();
}
return NULL ;
HOWTO: Know When the User Clicks a Check Box in a TreeView Control
ID: Q261289
SUMMARY
On a TreeView control with the TVS_CHECKBOXES style, there is no notification that the checked state of the item has been changed. There is also no notification that indicates that the state of the item has changed. However, you can determine that the user has clicked the state icon of the item and act upon that. MORE INFORMATION
When the user clicks the check box of a TreeView item, an NM_CLICK notification is sent to the parent window. When this occurs, the TVM_HITTEST message returns TVHT_ONITEMSTATEICON. The TreeView control uses this same condition to toggle the state of the check box. Unfortunately, the TreeView control toggles the state after the NM_CLICK notification is sent.You can post a user-defined message to the same window that is processing the NM_CLICK notification, and treat this user-defined message as a notification that the checked state has changed. Following is sample code that illustrates how this can be accomplished:
#define UM_CHECKSTATECHANGE (WM_USER + 100)case WM_NOTIFY:
{
LPNMHDR lpnmh = (LPNMHDR) lParam;
TVHITTESTINFO ht = {0};
if(lpnmh->code == NM_CLICK) && (lpnmh->idFrom == IDC_MYTREE))
{
DWORD dwpos = GetMessagePos(); // include <windowsx.h> and <windows.h> header files
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1); TreeView_HitTest(lpnmh->hwndFrom, &ht);
if(TVHT_ONITEMSTATEICON & ht.flags)
{
PostMessage(hWnd, UM_CHECKSTATECHANGE, 0, (LPARAM)ht.hItem);
}
}
}
break;case UM_CHECKSTATECHANGE:
{
HTREEITEM hItemChanged = (HTREEITEM)lParam;
/*
Retrieve the new checked state of the item and handle the notification.
*/
}
break; 至于要知道点的是那个item,可以用SetItemData为每个item设置一个程序能够理解的键值,利用这个键值判断相应应该执行的操作