How to display the item of a treectrl like this?
-
in a treectrl,when a root item is expanded , a kind of icon associated with the item is displayed,and when that root item is shrink,another kind of the icon is displayed. thank you
If you browse the Platform SDK, and look at the overview for Tree View controls, it has a few paragraphs about "Item States", which is what you are interested in. Look up these member functions / messages as well: CTreeCtrl::SetImageList (CImageList *, TVSIL_STATE) / TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)hImageList. Iain.
-
in a treectrl,when a root item is expanded , a kind of icon associated with the item is displayed,and when that root item is shrink,another kind of the icon is displayed. thank you
hi, create a imagelist .h CImageList m_cImageList; .cpp populate event() if (1) //bDoThisOnlyOnce m_cImageList.Create(IDB_TREEVIEW, 16, 10, RGB (255, 0, 255)); //IDB_TREEVIEW resource bitmap with a the all icons GetTreeCtrl().SetImageList(&m_cImageList, TVSIL_NORMAL); rootitem = GetTreeCtrl().InsertItem(TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, _T("RootItem"), ILI_CLOSED_FOLDER, ILI_CLOSED_FOLDER, 0, 0, -1, TVI_ROOT, TVI_SORT ); //ILI_CLOSED_FOLDER, ILI_CLOSED_FOLDER <- item nr of imagelist Add msg .h afx_msg void OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult); .cpp void CMyTreeView::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; HTREEITEM hItem = pNMTreeView->itemNew.hItem; CString string;string = GetPathFromItem (hItem); *pResult = FALSE; int inImage, inSelectedImage; if (pNMTreeView->action == TVE_EXPAND) { if (GetTreeCtrl().GetParentItem (hItem) == NULL ) { GetTreeCtrl().GetItemImage( hItem, inImage, inSelectedImage ); if (inImage == ILI_CLOSED_FOLDER && inSelectedImage == ILI_CLOSED_FOLDER) { GetTreeCtrl().SetItemImage( hItem, ILI_OPEN_FOLDER, ILI_OPEN_FOLDER); } } } else { // pNMTreeView->action == TVE_COLLAPSE if (GetTreeCtrl().GetParentItem (hItem) == NULL) { GetTreeCtrl().GetItemImage( hItem, inImage, inSelectedImage ); if (inImage == ILI_OPEN_FOLDER && inSelectedImage == ILI_OPEN_FOLDER) { GetTreeCtrl().SetItemImage( hItem, ILI_CLOSED_FOLDER, LI_CLOSED_FOLDER); } } } hope it helps dan o hope it helps