Thank you for your good health! It's 23:31:47, and I can't see the moon when I look up, but the wind is great. If there is a moon, it should be able to count as what Su Shi said: "The moon is clear. On such a good night, I learned the simple usage of the two controls.
The cimagelist control is used to save a group of icons or bitmaps of the same size. It has no graphic display interface and is mainly used to provide a graphical list for other controls. You can access icons or bitmaps through indexes. Common cimagelist functions include:
| Function |
Description |
| Create |
Create a cimagelist Control |
| Getimagecount |
Obtain the number of images |
| Getimageinfo |
Obtain image information |
| Add |
Add an image to the image list control |
| Remove |
Delete an image from the list |
| Replace |
Replace the specified image in the list |
For example:
Cimagelist m_imagelist;
// Create a cimagelist object
M_imagelist.create (16, 16, ilc_color8, 0, 4 );
// Load the icon
M_imagelist.add (afxgetapp ()-> loadicon (idi_icon_root ));
The ctreectrl is a tree-like list control that provides the ability to display data in a hierarchical structure. This control has a visual interface, which can be created through the interface editor. You only need to pull it to the interface. You can also create a tree list control through the create function, because this method is usually not used, I will not go into details here. In addition, this control also has many tree shapes, such as has button and has line. You can view and set them in the properties of the Interface Editor.
The tree control has two very important data structures: TV _item and TV _insertstruct. The former is used to describe the information of a tree node, and the latter describes the information required to insert a tree. The structure is as follows:
Typedef struct _ TV _item {
Uint mask; // The validity mask of the structure member.
Htreeitem hitem; // data item control handle
Uint state; // data item status
Uint statemask; // status validity blocking bit
Lpstr psztext; // data item name string
Int cchtextmax; // the maximum length of the data item name
Int iimage; // Index Number of the data item icon
Int iselectedimage; // Index Number of the selected data item icon
Int cChildren; // subitem ID
Lparam ;// Program Defined 32-Bit Data tvif_param
} TV _item, far * lptv_item;
Typedef struct _ TV _inser tstruct
{
Htreeitem hparent; // parent control handle
Htreeitem hinsertafter; // Insert the position of the tree item
TV _item item; // data item Structure
} TV _insertstruct, far * lptv_insertstruct;
Cimagelist allows you to conveniently provide icons for ctreectrl. First, set the chart list of the tree control:
M_treestruct.setimagelist (& m_imagelist, tvsil_normal );
Then, when adding a tree list node, you can set the icon index when the node is selected and the icon index when it is not selected. If no value is set, the data structure defaults to 0. The data structure is the preceding TV _item.
Add a root node to the tree control
Adding a root node is troublesome.CodeAs follows:
Tvinsertstruct tvinsert; // defines an insert structure
Htreeitem hparent; // used to save the inserted position
Tvinsert. hparent = NULL; // set the parent node to null.
Tvinsert. hinsertafter = NULL; // The node that was set earlier is also empty.
Tvinsert. item. Mask = tvif_text; // sets the mask.
Tvinsert. item. psztext = _ T ("company"); // The text to be displayed is "Company"
Hparent = m_treestruct.insertitem (& tvinsert); // Insert the tree structure and return the inserted position.
With the parent node hparent, it is convenient to insert the child node:
// Add the first-level project "Technology Department"
// Parameter list: displays text, selected icon indexes, unselected icon indexes, and htreeitem values of the parent node.
Htreeitem H1 = m_treestruct.insertitem ("Technology Department", 1, 2, hparent );
// Add sub-projects under the first-level project "School of Management", that is, level 2
M_treestruct.insertitem ("ERP group", 3,4, H1 );
M_treestruct.insertitem ("UI group", 3,4, H1 );
M_treestruct.insertitem ("core R & D group", 3,4, H1 );
// Add other first-level projects
M_treestruct.insertitem ("Sales Department", 1, 2, hparent );
Expand Tree nodes:
// Expand the first-level project
M_treestruct.expand (hparent, tve_expand );
Add a subnode to the selected node:
// Obtain the project selected by the tree control
Htreeitem hitem = m_treestruct.getselecteditem ();
// Obtain the index of the sub-project image of the selected project and the image index after the sub-project selection,
// Set the index of the newly added project
Int index, selindex;
M_treestruct.getitemimage (m_treestruct.getchilditem (hitem), index, selindex );
// Insert a new sub-project to the selected project
M_treestruct.insertitem (m_stritem, index, selindex, hitem );
// Expand the selected project to view the new subitem
M_treestruct.expand (hitem, tve_expand );
Delete selected nodes:
// Obtain the project selected by the tree control
Htreeitem hitem = m_treestruct.getselecteditem ();
// Delete the selected project and all its sub-items
M_treestruct.deleteitem (hitem );
Author: Hanjiang fishing
Source: grass house & land reclamation-Technical blog of Hanjiang fishing
The copyright of this article belongs to the author. You are welcome to repost this article, but you must keep this statement without the consent of the author.ArticleThe original text connection is clearly displayed on the page. Otherwise, the legal liability is retained.