
MFC树控件如何创建组,组里面有成员。
2013-09-01
展开全部
我也在学···不太懂,给你点代码参考一下: // TODO: Add extra initialization here
//创建CImageList对象
m_imageList.Create(16, 16, ILC_COLOR8, 0, 4);
//加载5个图标
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_ROOT));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_FIRST));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_FIRSTOPEN));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_SECOND));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_SECONDOPEN));
//向树形控件添加图像列表
m_treeSchool.SetImageList(&m_imageList,TVSIL_NORMAL);
//设置根节点
TVINSERTSTRUCT tvInsert;
HTREEITEM hParent;
tvInsert.hParent = NULL;
tvInsert.hInsertAfter = NULL;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = _T("大学");
hParent = m_treeSchool.InsertItem(&tvInsert);
//添加第一级项目"管理学院"
HTREEITEM h1 = m_treeSchool.InsertItem("管理学院",1,2,hParent);
//添加第一级项目"管理学院"下的子项目,即第二级
m_treeSchool.InsertItem("企业管理系",3,4,h1);
m_treeSchool.InsertItem("会计系",3,4,h1);
m_treeSchool.InsertItem("商学系",3,4,h1);
//添加其他第一级项目
m_treeSchool.InsertItem("经济学院",1,2,hParent);
m_treeSchool.InsertItem("文学院",1,2,hParent);
m_treeSchool.InsertItem("新闻学院",1,2,hParent);
m_treeSchool.InsertItem("艺术学院",1,2,hParent);
//展开第一级项目
m_treeSchool.Expand(hParent,TVE_EXPAND);
//创建CImageList对象
m_imageList.Create(16, 16, ILC_COLOR8, 0, 4);
//加载5个图标
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_ROOT));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_FIRST));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_FIRSTOPEN));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_SECOND));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_SECONDOPEN));
//向树形控件添加图像列表
m_treeSchool.SetImageList(&m_imageList,TVSIL_NORMAL);
//设置根节点
TVINSERTSTRUCT tvInsert;
HTREEITEM hParent;
tvInsert.hParent = NULL;
tvInsert.hInsertAfter = NULL;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = _T("大学");
hParent = m_treeSchool.InsertItem(&tvInsert);
//添加第一级项目"管理学院"
HTREEITEM h1 = m_treeSchool.InsertItem("管理学院",1,2,hParent);
//添加第一级项目"管理学院"下的子项目,即第二级
m_treeSchool.InsertItem("企业管理系",3,4,h1);
m_treeSchool.InsertItem("会计系",3,4,h1);
m_treeSchool.InsertItem("商学系",3,4,h1);
//添加其他第一级项目
m_treeSchool.InsertItem("经济学院",1,2,hParent);
m_treeSchool.InsertItem("文学院",1,2,hParent);
m_treeSchool.InsertItem("新闻学院",1,2,hParent);
m_treeSchool.InsertItem("艺术学院",1,2,hParent);
//展开第一级项目
m_treeSchool.Expand(hParent,TVE_EXPAND);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询