CTreeCtrl应用控件技巧-创建/编辑Edit/API的详细使用(代码详细介绍)

1,Inserts a new item in a tree view control.CTreeCtrl插入Item
HTREEITEM InsertItem(
   LPCTSTR lpszItem,
   HTREEITEM hParent = TVI_ROOT,
   HTREEITEM hInsertAfter = TVI_LAST 

);

例子:

void CTREE_GUI_CONTROLDlg::InitTreeControlSimple(){
	HTREEITEM h_Item1;
	h_Item1 = m_Tree_Simple.InsertItem(L"AlphaA", TVI_ROOT);
	// h_Item1 Children
	HTREEITEM h_Sub_Item1, h_Sub_Item2, h_Sub_Item3, h_Sub_Item4, h_Sub_Item5;
	h_Sub_Item1 = m_Tree_Simple.InsertItem(L"AA", h_Item1);
	h_Sub_Item2 = m_Tree_Simple.InsertItem(L"AB", h_Item1, h_Sub_Item1);
	h_Sub_Item3 = m_Tree_Simple.InsertItem(L"AC", h_Item1, h_Sub_Item2);
	h_Sub_Item4 = m_Tree_Simple.InsertItem(L"AD", h_Item1);
	h_Sub_Item5 = m_Tree_Simple.InsertItem(L"AE", h_Item1, TVI_FIRST);
	// h_Sub_Item5 Children
	HTREEITEM h_SubSub_Item51, h_SubSub_Item52, h_SubSub_Item53;
	h_SubSub_Item51 = m_Tree_Simple.InsertItem(L"AEA", h_Sub_Item5, TVI_FIRST);
	h_SubSub_Item52 = m_Tree_Simple.InsertItem(L"AEB", h_Sub_Item5, h_SubSub_Item51);
	h_SubSub_Item53 = m_Tree_Simple.InsertItem(L"AEC", h_Sub_Item5, h_SubSub_Item52);

	// h_Item2
	HTREEITEM h_Item2;
	h_Item2 = m_Tree_Simple.InsertItem(L"AlphaB", TVI_ROOT, h_Item1);
	// h_Item2 Children
	HTREEITEM h_Sub2_Item1, h_Sub2_Item2, h_Sub2_Item3, h_Sub2_Item4, h_Sub2_Item5;
	h_Sub2_Item1 = m_Tree_Simple.InsertItem(L"BA", h_Item2);
	h_Sub2_Item2 = m_Tree_Simple.InsertItem(L"BB", h_Item2);
	h_Sub2_Item3 = m_Tree_Simple.InsertItem(L"BC", h_Item2);
	h_Sub2_Item4 = m_Tree_Simple.InsertItem(L"BD", h_Item2);
	h_Sub2_Item5 = m_Tree_Simple.InsertItem(L"BE", h_Item2);

	// BkColor
	m_Tree_Simple.SetBkColor(RGB(250, 230, 200));
}


2,Inserts a new item in a tree view control.CTreeCtrl插入Item,基于ImageList

HTREEITEM InsertItem(
   LPCTSTR lpszItem,
   int nImage,
   int nSelectedImage,
   HTREEITEM hParent = TVI_ROOT,
   HTREEITEM hInsertAfter = TVI_LAST
);

例子:

void CTREE_GUI_CONTROLDlg::InitImagelist(){
	// 载入图标
	const int ICON_LENGTH = 3;
	HICON Icon[ICON_LENGTH]; 
	Icon[0] = AfxGetApp()->LoadIcon(IDI_ICON3);
	Icon[1] = AfxGetApp()->LoadIcon(IDI_ICON2);
	Icon[2] = AfxGetApp()->LoadIcon(IDI_ICON1);
	//创建图像列表控件
	m_Imagelist = new CImageList();
	m_Imagelist->Create(16, 16, ILC_COLOR4, 7, 7);
	m_Imagelist->SetBkColor(RGB(255, 255, 255));
	for (int n = 0; n<ICON_LENGTH; ++n){
		//把图标载入图像列表控件
		m_Imagelist->Add(Icon[n]); 
	}
}

void CTREE_GUI_CONTROLDlg::InitTreeControlColor(){
	//为Tree设置一个图像列表,使TreeControl控件的节点显示不同的图标
	m_Tree_Color.SetImageList(m_Imagelist, TVSIL_NORMAL);

	HTREEITEM h_Item1;
	h_Item1 = m_Tree_Color.InsertItem(L"AlphaA", 0, 1, TVI_ROOT);
	// h_Item1 Children
	HTREEITEM h_Sub_Item1, h_Sub_Item2, h_Sub_Item3, h_Sub_Item4, h_Sub_Item5;
	h_Sub_Item1 = m_Tree_Color.InsertItem(L"AA", 0, 1, h_Item1);
	h_Sub_Item2 = m_Tree_Color.InsertItem(L"AB", 1, 1, h_Item1, h_Sub_Item1);
	h_Sub_Item3 = m_Tree_Color.Inse
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值