The code-run effect is shown below:
First, the tree controls (Ctree control)
Tree control is used to display data items that have a certain hierarchy. Many applications use the control, such as the disk directory in the Explorer.
The tree control has a root data item (root item) that contains each child item under the root data item. The root data item is the father of all the child data items that are children of the root data item. All child data items are sibling (sibling) relationships. Each data item includes a data item name (a text string) and an image to represent the data item, which can also contain children under each data item, and the entire structure is like a tree.
Second, the use of tree control
In MFC, tree controls are encapsulated into CTreeCtrl classes. Let's talk about the creation, attributes, and manipulation of tree controls.
(1) Tree control creation
Tree control is generally used in dialog box programs. There are two ways to create a tree control, one is to create it statically, and one is to create it dynamically. Static creation is a member variable that is declared associated with a drag-and-drop control to manipulate tree control. Drag and drop a CTreeCtrl control on the dialog box program interface, and then add a member variable of the CTreeCtrl type by ClassWizard and use it in your program. Dynamic creation refers to creating a tree control object using the CREATE function in a program. This article uses the method of static creation.
(2) tree-controlled properties
Tree control has many property manipulation functions. You can use these functions to get the various attribute information that the tree controls. For example, obtains the number of items in the tree control GetCount, obtains the tree control the item relative to the parent item offset value GetIndent, obtains the tree control image List control handle getimagelist and so on. You can view MSDN help with specific information.
(3) control of the number of operations
Tree-controlled action methods include inserting a tree item insertitem, deleting a tree item deleteitem, deleting
All tree items Deleteallitems, expand, or close the child expand of the tree item, and select a specific tree item
SelectItem, select a tree item as the first visual tree item selectsetfirstvisible, edit a can
Depending on the tree item Editlabel and sort the subtree item SortChildren for the given parent tree item.