您好,登錄后才能下訂單哦!
初始化樹控件
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<m_stAllUserInfo.size();i++) { if (sMsg == m_stAllUserInfo[i].szName) { m_EditUserName.SetWindowText(sMsg); m_editPassword1.SetWindowText(m_stAllUserInfo[i].szPassWord); m_editPassword2.SetWindowText(m_stAllUserInfo[i].szPassWord); m_comLimits.SetCurSel(m_stAllUserInfo[i].nIdentity-1); } } } if (hItemSelect != NULL) { if (m_TreeUser.ItemHasChildren(hItemSelect)) { m_TreeUser.Expand(hItemSelect, TVE_EXPAND); } } *pResult = 0; }
創建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);
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。