Step One: Create an image
Add a bitmap to the resource editor that contains all the icon resources. The following, we use a 13x13 pixel bitmap resource, of course, you can also use different sizes of bitmap resources.
Step Two: Add a variable to the image list
Class Ctreectrlx:public CTreeCtrl
{
Construction
Public
CTREECTRLX ();
Attributes
Public
CImageList M_image;
:
:
:
}
Step three: Create and set up an image list
Call the Create () function, create an image list with the image ID and size given in step one, and set the image list with the SetImageList () function. The process is as follows:
M_tree.m_image. Create (Idb_outline, 1, RGB (255,255,255));
M_tree. SetImageList (& (M_tree.m_image), tvsil_normal);
When used, we call it in the OnInitDialog () function or the OnInitialUpdate () function.
Step four: For each project, specify the image
Once you have assigned an image list for your tree control, when you insert the item into your tree control, you can assign it an icon, and of course you can change it later. InsertItem () and setitemimage () can achieve the above purpose. Tree control requires two different values, one is the item is not selected value, one is the item is selected value, of course, two values can be the same.