Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to display the item of a treectrl like this?

How to display the item of a treectrl like this?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    allenhu
    wrote on last edited by
    #1

    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

    I D 2 Replies Last reply
    0
    • A allenhu

      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

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • A allenhu

        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

        D Offline
        D Offline
        dan o
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups