启用 ctreecntrl 树项中的复选框
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要打开和关闭单个树项目的复选框,您需要发送
TVM_SETITEM
消息,用于设置 TreeView 中项目的属性。文档说
wParam
必须为零,而lParam
是指向TVITEM
结构 包含新的项目属性。因此,真正的战斗是相应地填写
TVITEM
结构。以下是重要部分:hItem
成员必须包含要修改的树项的句柄。mask
成员应设置为TVIF_STATE
,这表明state
和stateMask
成员有效。您将使用这些来打开和关闭复选框。state
成员可以设置为 0,这将隐藏指定树项的复选框。要显示树项目的复选框,请设置
1 <<< 12.
. (有关详细信息,请参阅文档)。stateMask
成员应设置为TVIS_STATEIMAGEMASK
以指示您正在更改项目的状态图像索引。由于您已设置
mask
来指示您仅使用state
和stateMask
成员,因此您可以愉快地忽略其余成员。最后,一旦设置了
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 thelParam
is a pointer to aTVITEM
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:hItem
member must contain the handle to the tree item that you want to modify.mask
member should be set toTVIF_STATE
, which indicates that thestate
andstateMask
members are valid. Those are the ones you'll be using to turn checkboxes on and off.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).stateMask
member should be set toTVIS_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 thestate
andstateMask
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 standardSendMessage
function, or theTreeView_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.)