当前位置:网站首页>Cbcgptreectrlex control used by BCG
Cbcgptreectrlex control used by BCG
2022-07-21 12:01:00 【Spring buds and summer lotus_ seven hundred and twenty-eight mi】
The effect of the official example is as follows :
In fact, many effects can be developed without , I cut a lot , The basic functions are as follows :
Next, step by step, get this effect :
1、 New project , And drag the control pic control
2、 Define members , Initialize control
The header file :CBCGPTreeCtrlEx m_wndTree;
Implementation file :
BOOL CTreeCtrlDemoDlg::OnInitDialog()
{
CBCGPDialog::OnInitDialog();
UINT nTreeStyles = WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | TVS_LINESATROOT |
TVS_HASLINES | // The cable
TVS_HASBUTTONS | // There are buttons
TVS_CHECKBOXES | // With selection box
TVS_FULLROWSELECT; // Select the whole line , Be careful not to have TVS_EDITLABELS
//TVS_EDITLABELS; // Editable
m_wndTree.CreateOnPlaceHolder(this, IDC_TREE, 0, nTreeStyles);
{
m_wndTree.EnableHeader(BCGP_GRID_HEADER_SORT); // Show header 0 Means not to show
m_wndTree.EnableColumnAutoSize(TRUE); // Set column adaptive width
m_wndTree.EnableGridLines(TRUE);// Show gridline
m_wndTree.EnableAlternateRows(TRUE);//
}
{
m_wndTree.DeleteAllItems();
m_wndTree.DeleteAllColumns();
m_wndTree.InsertColumn(0, _T("Name"), 100);
m_wndTree.InsertColumn(1, _T("Size"), 100);
m_wndTree.SetHeaderAlign(1, HDF_RIGHT);
m_wndTree.SetColumnAlign(1, HDF_RIGHT);
HTREEITEM htItem = m_wndTree.InsertItem(_T("test1"));
m_wndTree.InsertItem(_T("test1_1"), htItem);
m_wndTree.InsertItem(_T("test2"));
m_wndTree.AdjustLayout();
}
return TRUE; // return TRUE unless you set the focus to a control
}
This is the time The part of the tree structure can be displayed completely
3、 In use , Maintain the tree
Add children :
void CTreeCtrlDemoDlg::OnBnClickedButton3()
{
// TODO: Add control notification handler code here
HTREEITEM hSelected = m_wndTree.GetSelectedItem();
HTREEITEM hNew = NULL;
LPCTSTR lpszItem = _T("New item");
// Insert as child item
{
if (hSelected == NULL)
{
return;
}
hNew = m_wndTree.InsertItem(lpszItem, hSelected, TVI_LAST);
}
m_wndTree.AdjustLayout();
m_wndTree.RedrawWindow();
m_wndTree.SelectItem(hNew);
// update the checkbox of the header control
m_wndTree.UpdateHeaderCheckbox();
CEdit* pEdit = m_wndTree.EditLabel(hNew);
if (pEdit != NULL)
{
ASSERT_VALID(pEdit);
pEdit->SetSel(0, -1); // Select All
}
}
Add peer :
void CTreeCtrlDemoDlg::OnBnClickedButton2()
{
// TODO: Add control notification handler code here
HTREEITEM hSelected = m_wndTree.GetSelectedItem();
HTREEITEM hNew = NULL;
LPCTSTR lpszItem = _T("New item");
{
// Insert after the currently selected item
if (hSelected != NULL)
{
HTREEITEM hParent = m_wndTree.GetParentItem(hSelected);
hNew = m_wndTree.InsertItem(lpszItem, hParent, hSelected);
}
// Insert as last
else
{
hNew = m_wndTree.InsertItem(lpszItem);
}
}
m_wndTree.AdjustLayout();
m_wndTree.RedrawWindow();
m_wndTree.SelectItem(hNew);
// update the checkbox of the header control
m_wndTree.UpdateHeaderCheckbox();
CEdit* pEdit = m_wndTree.EditLabel(hNew);
if (pEdit != NULL)
{
ASSERT_VALID(pEdit);
pEdit->SetSel(0, -1); // Select All
}
}
// Delete operation :
void CTreeCtrlDemoDlg::OnBnClickedButton1()
{
// TODO: Add control notification handler code here
HTREEITEM hSelected = m_wndTree.GetSelectedItem();
if (hSelected == NULL)
{
return;
}
m_wndTree.SelectItem(hSelected); // select only one item if multiple selection
m_wndTree.SelectSetFirstVisible(hSelected);
m_wndTree.RedrawWindow();
if (BCGPMessageBox(L"are you delete?", MB_YESNO) == IDYES)
{
HTREEITEM hNext = m_wndTree.GetNextItem(hSelected, TVGN_PREVIOUSVISIBLE);
m_wndTree.DeleteItem(hSelected);
m_wndTree.AdjustLayout();
m_wndTree.SelectItem(hNext);
}
}
// Expand all levels
void CTreeCtrlDemoDlg::ExpandTreeItem(CBCGPTreeCtrlEx &tree, HTREEITEM hItem, UINT nCode)
{
HTREEITEM hChild;
if (tree.ItemHasChildren(hItem))
{
tree.Expand(hItem, nCode);
hChild = tree.GetChildItem(hItem);
while (hChild)
{
ExpandTreeItem(tree, hChild, nCode);
hChild = tree.GetNextItem(hChild, TVGN_NEXT);
}
}
}
void CTreeCtrlDemoDlg::OnExpandAll()
{
HTREEITEM hItem = m_wndTree.GetRootItem();
while (hItem)
{
ExpandTreeItem(m_wndTree, hItem, TVE_EXPAND);
hItem = m_wndTree.GetNextItem(hItem, TVGN_NEXT);
}
}
Last , For example, operations are required after checking , At this time, you can refer to the expanded traversal
边栏推荐
- 【thymeleaf】基本对象:Base objects
- 如何在 FreeBSD 上设置 PF 防火墙来保护 Web 服务器
- WPS前骨干历时10年打造新型软件,Excel用户:我为此改用WPS
- Simulated exhaustive 731 My schedule II
- 让软件开发民主化的低代码
- Unity shader learning (V) mouse moving box
- Introduction to chrome plug-in development -- CSDN login free copy, attention free view
- AIX挂载NFS写入效率低的解决方案
- Introduction and main features of varnish cache proxy server
- Lenovo exposed new UEFI vulnerabilities, affecting 70 models and millions of laptops
猜你喜欢
线性回归模型笔记(2)
2021-9-21
Mongodb replication (replica set)
Reasons and solutions for more data entries than the original data table after left join/inner join
Lenovo exposed new UEFI vulnerabilities, affecting 70 models and millions of laptops
HTB-Lame
1. Mx6u system migration-4-uboot migration
The getsubmittedfilename() method is unavailable
sqlilabs less-26~26a
HBuilderX 格式化 不換行(import)
随机推荐
Simulated exhaustive 731 My schedule II
创建型模式之单例模式
【问题解决】 怎么传输文件到win服务器
Unity spritemask implementation
为什么 this.$refs[formName].validate((valid) =>{} 无效(没有反应)
2018全球半导体技术发明专利排行榜:京东方杀入前三,华为仅排第59位!
Solution 5 programming 2
"Fundamentals of program design" Chapter 10 function and program structure 7-1 circular volume calculator (20 points)
Why introduce threads?
"Fundamentals of program design" Chapter 10 function and program structure 6-4 recursive calculation of Fabonacci sequence (10 points)
期货网上开户安全吗,怎么开户啊,需要多少钱?
left join/inner join以后数据条数比原数据表多的原因及解决办法
HTB-Lame
Django queries the queryset object data of MySQL database and converts it into JSON string
HBuilderX 格式化 不换行(import)
sqlilabs less-26~26a
Leetcode 展望2021
Try to understand the essence of low code platform design from another angle
SSM integrates annotation mapping and XML Mapping
sqlilabs less-27