rwik
rwik

Reputation: 785

Enabling checkboxes in treeitems of 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?

Upvotes: 2

Views: 496

Answers (1)

Cody Gray
Cody Gray

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:

  • 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.)

Upvotes: 4

Related Questions