启用 ctreecntrl 树项中的复选框

发布于 2024-11-01 21:24:45 字数 102 浏览 0 评论 0原文

我正在尝试在 Visual C++ 6.0 的 ctreecntrl 中启用/禁用树项中的复选框。我找到了对所有项目执行此操作的选项,但无法对每个项目执行此操作。有什么功能可以做到这一点吗?

I am trying to enable/disable checkboxes in treeitems in ctreecntrl of visual c++ 6.0. I have found the options to do that for all items, but couldn't do that per item basis. Is there any function to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在夏天 2024-11-08 21:24:45

要打开和关闭单个树项目的复选框,您需要发送 TVM_SETITEM 消息,用于设置 TreeView 中项目的属性。

文档说 wParam 必须为零,而 lParam 是指向 TVITEM 结构 包含新的项目属性。

因此,真正的战斗是相应地填写 TVITEM 结构。以下是重要部分:

  • hItem 成员必须包含要修改的树项的句柄。
  • mask 成员应设置为 TVIF_STATE,这表明 statestateMask 成员有效。您将使用这些来打开和关闭复选框。
  • state 成员可以设置为 0,这将隐藏指定树项的复选框。
    显示树项目的复选框,请设置 1 <<< 12.. (有关详细信息,请参阅文档)。
  • stateMask 成员应设置为 TVIS_STATEIMAGEMASK 以指示您正在更改项目的状态图像索引。

由于您已设置 mask 来指示您仅使用 statestateMask 成员,因此您可以愉快地忽略其余成员。

最后,一旦设置了 TVITEM 结构,您就可以使用标准 SendMessage 函数,或 TreeView_SetItem,将消息发送到树项。

(当然,整个TreeView必须有TVS_CHECKBOXES style 设置以使上述任何一项都可以工作!但你说你已经知道如何做到这一点。)

To turn checkboxes on and off for individual tree items, you need to send TVM_SETITEM messages, which are used to set attributes for items in a TreeView.

The documentation says the wParam must be zero, and the lParam is a pointer to a TVITEM structure that contains the new item attributes.

So the real battle is in getting the TVITEM structure filled out accordingly. Here are the important parts:

  • The hItem member must contain the handle to the tree item that you want to modify.
  • The mask member should be set to TVIF_STATE, which indicates that the state and stateMask members are valid. Those are the ones you'll be using to turn checkboxes on and off.
  • The state member can be set to 0, which will hide the checkbox for the specified tree item.
    To show the checkbox for the tree item, set this member of 1 << 12. (See the docs for details).
  • The stateMask member should be set to TVIS_STATEIMAGEMASK to indicate that you're changing the item's state image index.

Since you've set mask to indicate that you're only using the state and stateMask members, you can happily ignore the rest of the members.

And finally, once you've got the TVITEM structure set, you can either use the standard SendMessage function, or the TreeView_SetItem macro, to send the message to the tree item.

(Of course, the entire TreeView must have the TVS_CHECKBOXES style set in order for any of the above to work! But you said you already figured out how to do that.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文