VC++控件之使用树控件

来源:互联网 发布:知乎 孔子姓什么 编辑:程序博客网 时间:2024/06/05 00:30

1、添加控件

 

 

  2、添加位图

 


三、添加变量

 

 

 

 

四、添加代码(红色部分)

BOOL CCTreeCtrlDlg::OnInitDialog()
{
CDialog::OnInitDialog();

ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
   CString strAboutMenu;
   strAboutMenu.LoadString(IDS_ABOUTBOX);
   if (!strAboutMenu.IsEmpty())
   {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
   }
}

SetIcon(m_hIcon, TRUE);    // Set big icon
SetIcon(m_hIcon, FALSE);   // Set small icon

// TODO: Add extra initialization here
    HTREEITEM root,root1,root2,root3;
    m_imagelist.Create(16,16,ILC_COLOR24|ILC_MASK,1,0);
    m_imagelist.Add(AfxGetApp()->LoadIcon(IDI_ICON4));
    m_imagelist.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
    m_imagelist.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
    m_imagelist.Add(AfxGetApp()->LoadIcon(IDI_ICON3));

    m_tessctrl.SetImageList(&m_imagelist,TVSIL_NORMAL);
    root=m_tessctrl.InsertItem("部门",0,0);
   root1=m_tessctrl.InsertItem("生产",1,1,root);
    root2=m_tessctrl.InsertItem("人事",2,2,root);
    root3=m_tessctrl.InsertItem("质检",3,3,root);
   m_tessctrl.InsertItem("长江",root1);
    m_tessctrl.InsertItem("黄河",root2);
    m_tessctrl.InsertItem("泰山",root3);

return TRUE; // return TRUE unless you set the focus to a control
}

五、编译

六、运行