CTreeCtrl的用法

CTreeCtrl的用法

1.取得或设定项目的信息.

BOOL CTreeCtrl::GetItem(TV_ITEM* pItem);
BOOL CTreeCtrl::SetItem(TV_ITEM* pItem);
BOOL CTreeCtrl::SetItem(HTREEITEM hItem,UINTnMask,LPCTSTR lpszItem,int Image,int nSelectedImage,UINT nState,UINT nStateMask,LPARAME lParam);

2.取得与设定项目的状态

UINT CTreeCtrl::GetItemState(HTREEITEM hItem,UINT sStateMask)const;
BOOL CTree Ctrl::SetItemState(HTREEITEM hItem,UINT nState,UINT nStateMask);

3.取得与设定项目的图形

BOOL CTreeCtrl::GetItemImage(HTREEITEM hItem,int& nImage,int& nSelectedImage)const;
BOOL CTreeCtrl::SetItemImage(HTREEITEM hItem,int nImage,int nSelectedImage);

4. 取得与设定项目的文本

CString CTreeCtrl::GetItemText(HTREEITEM,hItem)const;
BOOL CTreeCtrl::SetItemText(HTREEITEM hItem,LPCTSTR lpszItem);

5. 查询 CTreeCtrl 中项目的个数

UINT CTreeCtrl::GetCount();

6.查询hItem 的父项目的句柄

HTREEITEM CTreeCtrl::GetparenItem(HTREEITEM hItem);

7.查询hItem是否有子项

BOOL CTreeCtrl::ItemHasChildren(HTREEITEM hItem);

8.取得hItem 第一个子项的句柄

HTREEITEM CTreeCtrl::GetChildItem(HTREEITEM hItem);

9.查询排在hItem前后的兄弟项

HTREEITEM CTreeCtrl::GetPrevSiblingItem(HTREEITEM hItem);
HTREEITEM CTreeCtrl::GetNextSiblingItem(HTREEITEM hItem);

10.取得选中项的句柄 取得根项的句柄

HTREEITEM CTreeCtrl::GetSelectedItem();

HTREEITEM CTreeCtrl::GetRootItem();

HTREEITEM hItem=GetRootItem(); //获取根结点,可能会有多个根结点

ItemHasChildren(hParent) //判断结点是否有孩子结点

hItem=GetChildItem(hParent); //获取第一个子结点

hItem=GetNextSiblingItem(hItem)); //获取下一个兄弟结点结点

Expand(hItem,bExpand?TVE_EXPAND:TVE_COLLAPSE);//展开/叠起结点

Select(hItem,TVGN_FIRSTVISIBLE); //设置选中结点

CString str=GetItemText(hChild); //获取结点字符串信息

HTREEITEM hCurrSel = GetSelectedItem(); //获取当前选中结点

SelectItem(hNewSel);

HTREEITEM hNewSel = HitTest(pt, &nFlags); //判断坐标是否在当前结点范围内

HTREEITEM hItem=InsertItem(dlg.m_strItemText,hItemParent); //插入结点

//////////////////////////////////////////////////////////////////////////////////////////////////////

CTreeCtrl m_TripleTree;

CImageList m_imgList;
CImageList m_imgState;

/*
CImageList ImgTree;
ImgTree.Create (16,16,ILC_COLOR|ILC_MASK,3,3);//
创建图标列表 图标为单个图标
ImgTree.Add (AfxGetApp()->LoadIcon (IDI_CK));
ImgTree.Add (AfxGetApp()->LoadIcon (IDI_BASE_INFO));
ImgTree.Add (AfxGetApp()->LoadIcon (IDI_INPUT));
*/
m_imgList.Create(IDB_BITMAP_LIST,16, 1, RGB(255,255,255));//
创建图标列表 为连续的16*16图标
//m_imgState.Create(IDB_BITMAP_STATE,16, 1, RGB(255,255,255));//
创建状态图标
m_TripleTree.SetImageList(&m_imgList,TVSIL_NORMAL);//
选择与非选择
//m_TripleTree.SetImageList(&m_imgState,TVSIL_STATE);//
用户定义

HTREEITEM hItem1A=m_TripleTree.InsertItem(_T("根部"),0,0);
     
HTREEITEM hItem2_1B=m_TripleTree.InsertItem(_T("
根上一"),1,2,hItem1A,TVI_LAST);
m_TripleTree.InsertItem(_T("
根上二"1,2,hItem2_1B);
m_TripleTree.InsertItem(_T("
根上二"),1,2,hItem2_1B);

HTREEITEM hItem2_2B=m_TripleTree.InsertItem(_T("根上一"),1,2,hItem1A,TVI_LAST);
m_TripleTree.InsertItem(_T("
根上一"),1,2,hItem2_2B);
m_TripleTree.InsertItem(_T("
根上一"),1,2,hItem2_2B);

   m_TripleTree.InsertItem(_T("根上一"),1,2,hItem1A,TVI_LAST);
m_TripleTree.InsertItem(_T("
根上一"),1,2,hItem1A,TVI_LAST);
   
    //
设置显示风格
m_TripleTree.SetBkColor (RGB(220,200,220));//
背景颜色
m_TripleTree.Expand(hItem1A,TVE_EXPAND);//
根部展开
DWORD dwStyle=GetWindowLong(m_TripleTree.m_hWnd ,GWL_STYLE);//
获得树的信息
dwStyle|=TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT;//
设置风格
::SetWindowLong (m_TripleTree.m_hWnd ,GWL_STYLE,dwStyle);

你可能感兴趣的:(image,list,input,图形)