重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
初始化树控件
成都创新互联专业为企业提供独山网站建设、独山做网站、独山网站设计、独山网站制作等企业网站建设、网页设计与制作、独山企业网站模板建站服务,十年独山做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
VOID CScale3DCUserManageView::InitTree() { TVINSERTSTRUCT tvInsert; tvInsert.hParent = NULL; tvInsert.hInsertAfter = NULL; tvInsert.item.mask = TVIF_TEXT; tvInsert.item.pszText = _T("全部用户"); m_treeRoot = m_TreeUser.InsertItem(&tvInsert); //添加根节点 tvInsert.hParent = m_treeRoot; tvInsert.hInsertAfter = TVI_LAST; tvInsert.item.mask = TVIF_TEXT; tvInsert.item.pszText = _T("超级管理员"); m_itemSuperUser = m_TreeUser.InsertItem(&tvInsert); m_TreeUser.SetItemData(m_itemSuperUser, 0);//超级管理员节点 tvInsert.hParent = m_treeRoot; tvInsert.hInsertAfter = TVI_LAST; tvInsert.item.mask = TVIF_TEXT; tvInsert.item.pszText = _T("管理员"); m_itemAmdin = m_TreeUser.InsertItem(&tvInsert); m_TreeUser.SetItemData(m_itemAmdin, 0);//管理员节点 tvInsert.hParent = m_treeRoot; tvInsert.hInsertAfter = TVI_LAST; tvInsert.item.mask = TVIF_TEXT; tvInsert.item.pszText = _T("普通用户"); m_itemUser = m_TreeUser.InsertItem(&tvInsert); m_TreeUser.SetItemData(m_itemUser, 0);//超级管理员节点 }
点击树控件节点,获取节点信息
void CScale3DCUserManageView::OnNMClickTree1(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: 在此添加控件通知处理程序代码 CPoint pt; UINT nFlags; GetCursorPos(&pt); ::ScreenToClient(m_TreeUser.m_hWnd, &pt); HTREEITEM hItemSelect = m_TreeUser.HitTest(pt, &nFlags); CString sMsg= m_TreeUser.GetItemText(hItemSelect); INT nData = m_TreeUser.GetItemData(hItemSelect); if (1 == nData) { for (INT i=0;i创建CImageList给CTreeCtrl控件使用,如下:
void CScale3DCDeviceManageView::CreateImageList() { m_imgList.Create(35, 35, ILC_COLOR32 | ILC_MASK, 0, 2); //0.系统 CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP6); m_imgList.Add(&bmp,RGB(0xff,0xff,0xff)); //1.秤 bmp.DeleteObject(); bmp.LoadBitmap(IDB_BITMAP2); m_imgList.Add(&bmp, RGB(0xf1, 0xf7, 0xff)); //2.仪表 bmp.DeleteObject(); bmp.LoadBitmap(IDB_BITMAP7); m_imgList.Add(&bmp, RGB(0xf1, 0xf7, 0xff)); //3.print bmp.DeleteObject(); bmp.LoadBitmap(IDB_BITMAP8); m_imgList.Add(&bmp, RGB(0xf1, 0xf7, 0xff)); m_treeScale.SetImageList(&m_imgList, TVSIL_NORMAL);//绑定图标集合 }为指定节点设置图标,如下:
m_treeScale.SetItemImage(m_treeItemFirstScale, 1, 1);展开所有节点
VOID CScale3DCBillDesignView::MyExpandTree(HTREEITEM hTreeItem) {//展开节点 if (!m_treeBillFile.ItemHasChildren(hTreeItem)) { return; } HTREEITEM hNextItem = m_treeBillFile.GetChildItem(hTreeItem); while (hNextItem != NULL) { MyExpandTree(hNextItem); hNextItem = m_treeBillFile.GetNextItem(hNextItem, TVGN_NEXT); } m_treeBillFile.Expand(hTreeItem, TVE_EXPAND); }点击时某项时会闪烁
m_treeCtrl.SetExtendedStyle(TVS_EX_DOUBLEBUFFER, TVS_EX_DOUBLEBUFFER);
网站标题:树控件使用
文章网址:http://cqcxhl.com/article/jipddd.html