gpt4 book ai didi

mfc - 在 Windows XP 中单击项目复选框时,CTreeCtrl 'TVN_ITEMCHANGED ' 没有被触发?

转载 作者:行者123 更新时间:2023-12-02 17:36:02 28 4
gpt4 key购买 nike

我有一个树控件,树控件由一个根节点组成并且该根节点由一个子节点组成,而该子节点由 3 个节点组成。这个 treecontrol 在属性页上,在我点击任何复选框之后启用向导按钮。在 TVN_ITEMCHANGED 的事件处理程序中,我启用了工作表按钮。

当我运行我的应用程序并检查树控制的节点后,我无法启用工作表按钮。我在检查节点的检查状态时看到代码绝对没问题并启用工作表按钮。我开始调试我的代码,首先是 NM_CLICK 被解雇了然后我期待 TVN_ITEMCHANGED 事件被触发,但它根本没有被触发。

我不知道为什么这个事件没有被触发,我使用的环境是 WindowsXP

我已经在 windows7 ,windows 8,windows vista 上运行我的应用程序。它按预期工作,但仅在 XP 中我发现了这种行为。

谁能帮我解决这个问题。

最佳答案

根据 MSKB单击复选框时,您不会收到特定通知。

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.

引用那篇文章:

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;

关于mfc - 在 Windows XP 中单击项目复选框时,CTreeCtrl 'TVN_ITEMCHANGED ' 没有被触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26799283/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com