MFC使用TreeCtrl控件
2012-10-29 16:49
435 查看
在开发过程中TreeCtrl控件的使用也比较广泛,比如我们的资源浏览视图,我这里为大家分享一下我使用TreeCtrl控件的一些技巧。
1.我们新建一个Dlg对话框MFC程序
2.拖入一个TreeCtrl控件,控件ID修改为IDC_TREE,把控件的Has Lines属性选择为True(这样能让根与根下的Item有连接线),把控件的Has Buttons属性选择为True(这样可以在父项中显示加减号)如果还需要复选框的话把Check Boxes属性选择为True就可以了。
3.为TreeCtrl控件关键CTreeCtrl变量m_treectrl
4.在dlg的OnInitDialog输入以下代码:
1.我们新建一个Dlg对话框MFC程序
2.拖入一个TreeCtrl控件,控件ID修改为IDC_TREE,把控件的Has Lines属性选择为True(这样能让根与根下的Item有连接线),把控件的Has Buttons属性选择为True(这样可以在父项中显示加减号)如果还需要复选框的话把Check Boxes属性选择为True就可以了。
3.为TreeCtrl控件关键CTreeCtrl变量m_treectrl
4.在dlg的OnInitDialog输入以下代码:
CImageList m_list; m_list.Create(16,16,ILC_COLOR24,10,0); m_list.SetBkColor(RGB(255,255,255)); m_list.Add(AfxGetApp()->LoadIcon(IDI_ACCORD));//加载图标 m_list.Add(AfxGetApp()->LoadIcon(IDI_AUTO)); m_list.Add(AfxGetApp()->LoadIcon(IDI_AUTOCOMPUTER)); m_list.Add(AfxGetApp()->LoadIcon(IDI_CAMERA)); m_Tree_File.SetImageList(&m_list, TVSIL_NORMAL); HTREEITEM hRootComputer = m_Tree_File.InsertItem(_T("我的电脑"),0,1); //插入根项 HTREEITEM hRootAuto = m_Tree_File.InsertItem(_T("自动上线主机"),2,3); //插入根项 HTREEITEM hRootFind = m_Tree_File.InsertItem(_T("符合条件主机"),1,2); //插入根项 HTREEITEM hRootComputer_C = m_Tree_File.InsertItem(_T("C:"),1,1,hRootComputer); //在根项中插入子项 HTREEITEM hRootComputer_D = m_Tree_File.InsertItem(_T("D:"),1,1,hRootComputer); //在根项中插入子项 HTREEITEM hRootComputer_E = m_Tree_File.InsertItem(_T("E:"),1,1,hRootComputer); //在根项中插入子项 HTREEITEM hRootComputer_F = m_Tree_File.InsertItem(_T("F:"),1,1,hRootComputer); //在根项中插入子项 m_Tree_File.InsertItem(_T("文件"),2,4,hRootComputer_C); //在子项中插入子项 m_Tree_File.InsertItem(_T("文件"),2,4,hRootComputer_D); //在子项中插入子项 m_Tree_File.InsertItem(_T("文件"),2,4,hRootComputer_E); //在子项中插入子项 m_Tree_File.InsertItem(_T("文件"),2,4,hRootComputer_F); //在子项中插入子项 m_Tree_File.Expand(hRootComputer,TVE_EXPAND);//让根项自动展开 m_list.Detach();现在运行一下程序看一下效果,关于API的详细参数说明,大家可以看一下MSDN!
相关文章推荐
- VC/MFC之TreeCtrl控件使用经验总结(转帖)
- MFC一一TreeCtrl树控件的使用
- VC/MFC之TreeCtrl控件使用经验总结
- MFC/控件使用个之TREEctrl
- MFC TreeCtrl 控件(一):简单使用
- MFC TreeCtrl 控件(一):简单使用
- VC/MFC之TreeCtrl控件使用经验总结
- VC/MFC之TreeCtrl控件使用经验总结
- MFC中Tab控件的使用方法
- MFC Tab Control控件的详细使用
- VC/MFC之ListCtrl控件使用经验总结
- MFC中ListControl控件的使用
- vs2010 mfc项目配置属性的字符集为Unicode和多字节时,两者转换后使用的控件外观不一样
- MFC表格控件的简单使用
- MFC中使用TAB Control控件(转)
- 回调函数中使用MFC类的成员或对话框控件的简单方法
- 使用VS2010开发ActiveX(MFC)控件(1)——创建
- MFC Month Calendar Control 控件使用
- MFC中使用浏览器控件
- VC/MFC中的CComboBox控件使用详解