常用控件:TreeCtrl

1.定义根节点

#define TREE_ROOR_TEXT  "工程列表"
HTREEITEM hProjectRoot = NULL; // 树的根节点的句柄

2.头文件中定义控件变量

CTreeCtrl m_ProListTree;

2.适当位置插入根节点

if (hProjectRoot == NULL) {
        m_ProListTree.DeleteAllItems();
        hProjectRoot = m_ProListTree.InsertItem(_T(TREE_ROOR_TEXT), 0, 0);// 插入根节点
}

3.定义两级分支

HTREEITEM hFirst = NULL;
HTREEITEM hSecond = NULL;

4.插入分支节点

hFirst = hProjectRoot;
if(hFirst != NULL)
    hSecond = m_ProListTree.InsertItem(_T("子分支"), 1, 1, hFirst, TVI_LAST);

5.选择已插入分支

if(hSecond != NULL)
    m_ProListTree.SelectItem(hSecond);

你可能感兴趣的:(常用控件:TreeCtrl)