Reputation: 785
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?
Upvotes: 2
Views: 496
Reputation: 244692
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:
hItem
member must contain the handle to the tree item that you want to modify.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.state
member can be set to 0, which will hide the checkbox for the specified tree item.1 << 12
. (See the docs for details).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.)
Upvotes: 4