1.加载图标
HICON hic1 = theApp.LoadIcon(IDI_ICON1);
HICON hic2 = theApp.LoadIcon(IDI_ICON2);
2.创建图形列表
m_cimage不能为局部变量
m_cimage.Create(32, 32, ILC_COLOR32, 2, 2);
m_cimage.Add(hic1);
m_cimage.Add(hic2);
3.绑定图形列表到树形控件
CTreeCtrl* pctc = (CTreeCtrl*)(GetDlgItem(IDC_TREE1));
pctc->SetImageList(&m_cimage, TVSIL_NORMAL);
4.添加节点
HTREEITEM hroot=pctc->InsertItem(TEXT("parent1"), 0, 0);
HTREEITEM ht=pctc->InsertItem(TEXT("son1"), 1,1,hroot, TVI_LAST);
pctc->SetItemData(ht, 1);
ht=pctc->InsertItem(TEXT("son2"), hroot, TVI_LAST);
pctc->SetItemData(ht, 2);
hroot = pctc->InsertItem(TEXT("parent2"), 0, hroot);
ht = pctc->InsertItem(TEXT("son1"), 1, 1, hroot, TVI_LAST);
pctc->SetItemData(ht, 1);
ht = pctc->InsertItem(TEXT("son2"), 1, 1, hroot, TVI_LAST);
pctc->SetItemData(ht, 2);
5.运行效果

7210



被折叠的 条评论
为什么被折叠?



