Tree-View Item States Overview
Each item in a tree-view control has a current state. For example, an item can be selected, disabled, expanded, and so on. For the most part, the tree-view control automatically sets an item's state to reflect user actions, such as selection of an item. However, you can also set an item's state by using the TVM_SETITEM message and retrieve the current state of an item by using the TVM_GETITEM message. For a complete list of item states, see Tree-View Item States.
An item's current state is specified by the state member of the TV_ITEM structure. A tree-view control might change an item's state to reflect a user action, such as selecting the item or setting the focus to the item. In addition, an application might change an item's state to disable or hide the item or to specify an overlay image or state image.
When you specify or change an item's state, the stateMask member of TV_ITEM specifies which state bits to set, and the state member contains the new values for those bits. To set an item's overlay image, stateMask must include the TVIS_OVERLAYMASK value, and state must include the one-based index of the overlay image shifted left eight bits by using the INDEXTOOVERLAYMASK macro. The index can be zero to specify no overlay image. The overlay image must have been added to the tree-view control's list of overlay images by a previous call to the ImageList_SetOverlayImage function. The function specifies the one-based index of the image to add; this is the index used with the INDEXTOOVERLAYMASK macro. A tree-view control can have up to four overlay images.
To set an item's state image, stateMask of TV_ITEM must include the TVIS_STATEIMAGEMASK value, and state must include the one-based index of the state image shifted left twelve bits by using the INDEXTOSTATEIMAGEMASK macro. The index can be zero to specify no state image. For more information about overlay and state images, see Tree-View Image Lists.