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?
I am trying to enable/disable checkboxes in treeitems in ctreecntrl of visual c++ 6.0.
Share
To turn checkboxes on and off for individual tree items, you need to send
TVM_SETITEMmessages, which are used to set attributes for items in a TreeView.The documentation says the
wParammust be zero, and thelParamis a pointer to aTVITEMstructure that contains the new item attributes.So the real battle is in getting the
TVITEMstructure filled out accordingly. Here are the important parts:hItemmember must contain the handle to the tree item that you want to modify.maskmember should be set toTVIF_STATE, which indicates that thestateandstateMaskmembers are valid. Those are the ones you’ll be using to turn checkboxes on and off.statemember 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).stateMaskmember should be set toTVIS_STATEIMAGEMASKto indicate that you’re changing the item’s state image index.Since you’ve set
maskto indicate that you’re only using thestateandstateMaskmembers, you can happily ignore the rest of the members.And finally, once you’ve got the
TVITEMstructure set, you can either use the standardSendMessagefunction, or theTreeView_SetItemmacro, to send the message to the tree item.(Of course, the entire TreeView must have the
TVS_CHECKBOXESstyle set in order for any of the above to work! But you said you already figured out how to do that.)