Set status icons for tree control

Source: Internet
Author: User

 

 

Step 1: create an image

 

Add a bitmap containing all the ICON resources to the resource editor. The following column, we use13X13 pixel bitmap resources, of course, you can also use bitmap resources of different sizes.

 

Step 2: add variables to the image list

Class CTreeCtrlX: public CTreeCtrl

{

// Construction

Public:

CTreeCtrlX ();

 

// Attributes

Public:

CImageList m_imageState;

:

:

:

 

}

Step 3: Create and set the image list

 

CallCreate () function, Create an image list with the image ID and size given in step 1, and use SetImageList () function to set the image list. The process is as follows:

M_tree.m_imageState.Create (IDB_STATE, 13, 1, RGB (255,255,255 ));

M_tree.SetImageList (& (m_tree.m_imageState), TVSIL_STATE );

When usingThe OnInitDialog () function or OnInitialUpdate () function calls it.

 

Step 4: Specify the status image for each project

Once an image list is assigned to your tree control, you can specify a status icon for the project when you insert it to your tree control.The SetItemState () function can achieve the above purpose. Here we will use the INDEXTOSTATEIMAGEMASK () macro to re-sort the index value.

 

// Using TV _INSERTSTRUCT

CString str = "xyzASDFqwerZCV ";

TV _INSERTSTRUCT TV _is;

TV _is.hParent = parent? Parent: TVI_ROOT;

TV _is.hInsertAfter = TVI_LAST;

TV _is.item.mask = TVIF_TEXT | TVIF_STATE;

TV _is.item.stateMask = TVIS_STATEIMAGEMASK;

TV _is.item.state = INDEXTOSTATEIMAGEMASK (1 );

TV _is.item.pszText = str. GetBuffer (1 );

TV _is.item.cchTextMax = str. GetLength ();

HItem = InsertItem (& TV _is );

Str. ReleaseBuffer ();

 

// Using SetItemState

SetItemState (hItem, INDEXTOSTATEIMAGEMASK (1), TVIS_STATEIMAGEMASK );

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.