Home > Software engineering >  MFC cTreeCtrl controls
MFC cTreeCtrl controls

Time:09-27

Static create of control is the default, please double click the plus and minus sign folding and unfolding?
I now control click can fold, moreover is disorderly, excuse me, how to solve the problem,
How to return to the default state,

CodePudding user response:

Requirements:
Have access to a tree, no trees make any changes, just add a check box to check what is selected,
Then look at the default double-click fold open line under
How should manage?

CodePudding user response:

Resources to add TVS_CHECKBOXES style has both the CheckBox CheckBox

On the MSDN example
 
/*
Working with the state image indexes
There is, confusion about how to set and retrieve the state image index in a tree view control. The following examples demonstrate the proper method for setting and retrieving the state image index. The examples assume that There are only two state image indexes in the tree view control, unchecked and checked. If your application contains more than two, these functions provides will need to be modified to handle that case.

The following example function illustrates how to set an item 's check state.
*/
BOOL TreeView_SetCheckState (HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck)
{
TVITEM TVITEM;

TvItem. Mask=TVIF_HANDLE | TVIF_STATE;
TvItem. HItem=hItem;
TvItem. StateMask=TVIS_STATEIMAGEMASK;

/*
Since the state images are one - -based, 1 in this macro turns the check off, and
2 turns it on.
*/
TvItem. State=INDEXTOSTATEIMAGEMASK ((fCheck? 2:1));

Return TreeView_SetItem (hwndTreeView, & amp; TvItem);
}


The following example function illustrates how to retrieve an item 's check state.

BOOL TreeView_GetCheckState (HWND hwndTreeView, HTREEITEM hItem)
{
TVITEM TVITEM;

//Prepare to receive the desired information.
TvItem. Mask=TVIF_HANDLE | TVIF_STATE;
TvItem. HItem=hItem;
TvItem. StateMask=TVIS_STATEIMAGEMASK;

//Request the information.
TreeView_GetItem (hwndTreeView, & amp; TvItem);

//Return zero if it 's not checked, the or nonzero otherwise.
Return ((BOOL) (tvItem. State & gt;> 12) - 1);
}