CTREECTRL tree control introduction in VC ++

xiaoxiao2021-03-05  29

ListCtrl is used in a large number of systems, such as Windows Explorer is a typical example.

ListCtrl Tree Control Function Description: The structure of the tree can be used in the tree, where there is a root point (root) and then there are many sub-nodes, while each sub-node has one or more or no sub-nodes. The CTreeCtrl class is used in the MFC to encapsulate various operations of the tree control.

Call method:

Bool Create (DWORD DWSTYLE, CONST RECT & RECT, CWND * PPARENTWND, UINT NID);

Create a window, you can use the special style of the following tree controls in DWStyle:

Drawing between tvs_haslines between parent / sub-nodes

Tvs_LinesTroot Drawing between root / sub-nodes

TVS_HASBUTTONS Add a button before each node is used to indicate whether the current node has been expanded.

The display character of the TVS_Editlabels node can be edited

TVS_ShowseLalways also displays the current node when the focus is lost

TVS_DISABLEDRAGDROP does not allow DRAG / DROP

TVS_notoolTIPS does not use Tooltip display node display characters

Each node in the tree control has a handle (htreeItem), and the parameters that must be provided at the same time are the parent sideways of the node.

HtreeItem INSERTITEM (LPCTSTR LPSZITEM, HTREEITEM HPARENT = TVi_root, HtreeItem HinsetAfter = TVi_Last);

You can add a node, PSZITEM is the displayed character, HParent represents the handle of the parent node, the currently added node will be behind the nodes represented by the HinsertAfter, return the value of the currently created node. Handle

Tree control image list

Each of the Tree Control (CTREECTRL) can have a pair of bitmapped images associated with it. These images appear on the left side of the item tag. If this item is selected, an image will be displayed; another image is displayed if this item is not selected. For example, a certain item may display an open folder at selected, while the closed folder is displayed at the time of being selected.

To use item images, you must create a list of images by constructing a CIMAGELIST object and using the CIMAGELIST :: Create function. Then, add the desired bitmap to the created list, if you want to add a small icon before each node, you must call CIMAGELIST * SETIMAGELIST (CIMAGELIST * PIMAGELIST, INT NIMAGELISTTYPE); indicating the currently used ImageList, NIMAGELISTTYPE is TVSIL_NORMAL. Use the picture in the call to complete the image to be used in the image of ImageList. Then call HTREEITEM InsertItem (LPCTSTR lpszItem, int nImage, int nSelectedImage, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST); add node, nImage as a picture ID is used when the node is not selected, nSelectedImage when the node is selected by Use the picture number.

Profile:

转载请注明原文地址:https://www.9cbs.com/read-34126.html

New Post(0)