VC6使用CTreeCtrl目录

使用CTreeCtrl,主要是分两步,一步是设置展开与收起的图标,还有就是往目录树里面添加数据。

一般需要设置控件的属性:Has lines, lines at root,

下面是一个简单的例子:

BOOL InitMytree()
{
	//节点的图标	 
	int i=0;
	int i_count=2;
	//载入图标
	HICON icon[4];
	icon[0]=AfxGetApp()->LoadIcon (IDI_ICON2); 
	icon[1]=AfxGetApp()->LoadIcon (IDI_ICON1);
	
	//创建图像列表控件
	m_imagelist=new CImageList; 
	m_imagelist->Create(16,16,ILC_COLOR8|ILC_MASK,1,1);
	m_imagelist->SetBkColor (RGB(255,255,255));
	for(int n=0;n<i_count;n++)
	{
		m_imagelist->Add(icon[n]);  //把图标载入图像列表控件
	}
	m_Tree.SetImageList(m_imagelist,TVSIL_NORMAL);  
	//为m_Tree设置一个图像列表,使CtreeCtrl的节点显示不同的图标 
	m_Tree.SetBkColor(RGB(255,255,255));
	//设置m_Tree的背景色
	
	//创建节点
	//父节点
	HTREEITEM root=m_Tree.InsertItem("所有",0,1,TVI_ROOT,TVI_LAST);
	
	//一层子节点
	HTREEITEM root1=m_Tree.InsertItem("1区",0,1,root,TVI_LAST);
	HTREEITEM root2=m_Tree.InsertItem("2区",0,1,root,TVI_LAST);
	HTREEITEM root3=m_Tree.InsertItem("2区",0,1,root,TVI_LAST);
	
	
	//二层孙子节点
	m_Tree.InsertItem("1-1区",0,1,root1,TVI_LAST);
	m_Tree.InsertItem("1-2区",0,1,root1,TVI_LAST);
	m_Tree.InsertItem("1-3区",0,1,root1,TVI_LAST);
	m_Tree.InsertItem("1-4区",0,1,root1,TVI_LAST);
	m_DefaultItem = m_Tree.InsertItem("1-5区",0,1,root1,TVI_LAST);
	
	//二层孙子节点
	m_Tree.InsertItem("2-1区",0,1,root2,TVI_LAST);
	m_Tree.InsertItem("2-2区",0,1,root2,TVI_LAST);
	m_Tree.InsertItem("2-3区",0,1,root2,TVI_LAST);
	m_Tree.InsertItem("2-4区",0,1,root2,TVI_LAST);
	m_Tree.InsertItem("2-5区",0,1,root2,TVI_LAST);
	
	//二层孙子节点
	m_Tree.InsertItem("3-1区",0,1,root3,TVI_LAST);
	m_Tree.InsertItem("3-2区",0,1,root3,TVI_LAST);
	m_Tree.InsertItem("3-2区",0,1,root3,TVI_LAST);
	m_Tree.InsertItem("3-4区",0,1,root3,TVI_LAST);
	
	m_Tree.Expand(root, TVE_EXPAND);
	m_Tree.Expand(root1, TVE_EXPAND);
	m_Tree.Expand(root2, TVE_EXPAND);
	m_Tree.Expand(root3, TVE_EXPAND);

	m_Tree.SelectItem(m_DefaultItem);

	return true;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值