CTreeCtrl图标使用方法

本文详细介绍如何在CTreeCtrl控件中使用图标,包括加载图标资源、创建图像列表、设置图像列表及在树节点中指定图标的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



建立一个CTreeCtrl控制成员 m_Tree;

使用图标的方法:

Step0:  

CImageList *ImageList4Tree ;


Step1:   //load icon

HICON icon[4];

Icon[0]=AfxGetApp()->LoadIcon(IDI_ICON1);

Icon[1]=AfxGetApp()->LoadIcon(IDI_ICON2);


Step2: //创建CImageList

ImageList4Tree = new CImageList;

ImageList4Tree->Create(16,16,0,4,4); //16,16为图标分辩率,4,4为该list最多能容纳的图标数

For(int i=0;i<2;i++)

{

       ImageList4Tree->Add(Icon[i]); //读入图标

}

Step3: //使用创建好的CImageList

m_Tree.SetImageList(ImageList4Tree, TVSIL_NORMAL);

函数说明:

CTreeCtrl::SetImageList

CImageList* SetImageList( CImageList * pImageList, int nImageListType );

返回值

Pointer to the previous image list, if any; otherwise NULL.

返回指向先前的图像列表的指针(如果有);否则返回NULL

参数说明

pImageList

Pointer to the image list to assign. If pImageList is NULL, all images are removed from the tree view control.

指向要被分配的图像列表的指针。如果pImageList是NULL,则从tree view控件中删除所有的图像。

nImageListType

Type of image list to set. The image list can be one of the following values:

要设置的图像列表的类型。图像列表可以是下列值之一:l TVSIL_NORMAL 获取常规的图像列表,它包含了该tree view项的被选择的和不被选择的图像。l TVSIL_STATE 获取状态图像列表,它包含了处于用户定义状态的treeview项的图像。

  • TVSIL_NORMAL   Sets the normal image list, which contains the selected and nonselected images for the tree view item.
  • TVSIL_STATE   Sets the state image list, which contains the images for tree view items that are in a user-defined state.

备注

Call this function to set the normal or state image list for a tree view control and redraw the control using the new images.

此成员函数用来设置一个tree view控件的常规或状态图像列表,并使用新的图


Step4: //在添加项的同时选用图标

m_Tree.InsertItem(itemName,0,1,parentItem); //2个参数是item在添加好后的图标                                                                         //3个参数为item在被选中后的图标

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值