想要得到这个格式的程序
主要代码如下:
HTREEITEM root=m_ctlTree.InsertItem(L"清华大学",1,0,TVI_ROOT);//添加一级结点
HTREEITEM hd1=m_ctlTree.InsertItem(L"机械工程学院",1,0,root);//添加二级结点
HTREEITEM hd2=m_ctlTree.InsertItem(L"理学院",1,0,root);//添加二级结点
HTREEITEM hd3=m_ctlTree.InsertItem(L"经济管理学院",1,0,root);//添加二级结点
HTREEITEM h111=m_ctlTree.InsertItem(L"机械工程系",1,0,hd1);//添加三级结点
HTREEITEM h121=m_ctlTree.InsertItem(L"精仪系 ",1,0,hd2);//添加三级结点
HTREEITEM h131=m_ctlTree.InsertItem(L"汽车系",1,0,hd2);//添加三级结点
HTREEITEM h211=m_ctlTree.InsertItem(L"应用物理系",1,0,hd2);//添加三级结点
HTREEITEM h221=m_ctlTree.InsertItem(L"数学系",1,0,hd3);//添加三级结点
m_ctlTree.SetBkColor(RGB(200,200,255));//设置树形控件的背景色
m_ctlTree.SetTextColor(RGB(127,0,0));//设置文本颜色
m_ctlTree.Select(hd1,TVGN_CARET);
代码写在初始化中(OnInitDialog())
如果出来之后每个名称之前没有“+”你别忘记该变树形控件的相应属性:Has ines 和 Lines At Root 为True
相应的程序在资源里