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. CImageList for CTreeCtrl

CImageList for CTreeCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
9 Posts 4 Posters 1 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
    anu_88
    wrote on last edited by
    #1

    Hai How can we set images for items on CtreeCtrl Thanks in advance.:)

    A F H 3 Replies Last reply
    0
    • A anu_88

      Hai How can we set images for items on CtreeCtrl Thanks in advance.:)

      A Offline
      A Offline
      Abhi Lahare
      wrote on last edited by
      #2

      SetItem( TVITEM* pItem ) Regards Abhi Lahare

      1 Reply Last reply
      0
      • A anu_88

        Hai How can we set images for items on CtreeCtrl Thanks in advance.:)

        F Offline
        F Offline
        FarPointer
        wrote on last edited by
        #3

        you need to use CImageList* SetImageList( CImageList * pImageList, int nImageListType ); before you do insertitem and in that pass the index in the imagelist you need to display . Regards, FarPointer Blog:FARPOINTER

        1 Reply Last reply
        0
        • A anu_88

          Hai How can we set images for items on CtreeCtrl Thanks in advance.:)

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          See SetItem and SetImageList_**


          **_

          whitesky


          A 1 Reply Last reply
          0
          • H Hamid Taebi

            See SetItem and SetImageList_**


            **_

            whitesky


            A Offline
            A Offline
            anu_88
            wrote on last edited by
            #5

            Thanks for your reply.I got it. But when I insert items I am getting all the items as root items.How can I insert child items in to the tree :confused: -- modified at 3:02 Monday 10th July, 2006

            H 1 Reply Last reply
            0
            • A anu_88

              Thanks for your reply.I got it. But when I insert items I am getting all the items as root items.How can I insert child items in to the tree :confused: -- modified at 3:02 Monday 10th July, 2006

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              Can you show how you to use this function_**


              **_

              whitesky


              A 1 Reply Last reply
              0
              • H Hamid Taebi

                Can you show how you to use this function_**


                **_

                whitesky


                A Offline
                A Offline
                anu_88
                wrote on last edited by
                #7

                BOOL CBmDialog::OnInitDialog() { CDialog::OnInitDialog(); CImageList list; list.Create(16, 16, ILC_COLOR8, 0, 4); CBitmap bm; bm.LoadBitmap(IDB_BITMAP1); list.Add(&bm, RGB(0, 0, 0)); m_tree1.SetImageList(&list,TVSIL_NORMAL); m_tree1.InsertItem("Image1"); m_tree1.InsertItem("Image2"); HTREEITEM h1,h2; h2=m_tree1.GetNextItem(h1,TVGN_FIRSTVISIBLE); m_tree1.SetItemImage(h2,0,0); return TRUE; }

                H 1 Reply Last reply
                0
                • A anu_88

                  BOOL CBmDialog::OnInitDialog() { CDialog::OnInitDialog(); CImageList list; list.Create(16, 16, ILC_COLOR8, 0, 4); CBitmap bm; bm.LoadBitmap(IDB_BITMAP1); list.Add(&bm, RGB(0, 0, 0)); m_tree1.SetImageList(&list,TVSIL_NORMAL); m_tree1.InsertItem("Image1"); m_tree1.InsertItem("Image2"); HTREEITEM h1,h2; h2=m_tree1.GetNextItem(h1,TVGN_FIRSTVISIBLE); m_tree1.SetItemImage(h2,0,0); return TRUE; }

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #8

                  I test this code and it work (you need to a resource(bitmap))

                  	TVINSERTSTRUCT	TreeCtrlItem;
                  	CBitmap Bmp;
                  	CImageList *m_ImageList;
                  	HTREEITEM hTreeItem1;
                  	m_ImageList = new CImageList();
                  	m_ImageList->Create(50,50, ILC_COLORDDB,0,0);
                  		Bmp.LoadBitmap(IDB_BITMAP1);//resource bitmap with 5 image on it
                  
                  		m_ImageList->Add(&Bmp,RGB(155,155,155));
                  
                  	TreeCtrlItem.hParent = TVI_ROOT;
                  	TreeCtrlItem.hInsertAfter = TVI_LAST;
                  	TreeCtrlItem.item.mask = TVIF_TEXT |TVIF_IMAGE|TVIF_SELECTEDIMAGE;
                  
                  	TreeCtrlItem.item.pszText = CA2T("(A)");;//if you use from VS2005 instead CA2T use LPTSTR();
                  	TreeCtrlItem.item.lParam = 0;
                  	TreeCtrlItem.item.iImage=0;
                  	TreeCtrlItem.item.iSelectedImage=0;
                  	hTreeItem1 = m_Tree1.InsertItem(&TreeCtrlItem);
                  		m_Tree1.SetImageList(m_ImageList, LVSIL_NORMAL);
                  
                  	TreeCtrlItem.hParent = hTreeItem1;
                  	TreeCtrlItem.item.pszText = CA2T(" (B)");
                  	TreeCtrlItem.item.lParam = 1;
                  	TreeCtrlItem.item.iImage=1;
                  	TreeCtrlItem.item.iSelectedImage=1;
                  	m_Tree1.InsertItem(&TreeCtrlItem);
                  	m_Tree1.SetImageList(m_ImageList, LVSIL_NORMAL);
                  

                  _**


                  **_

                  whitesky


                  A 1 Reply Last reply
                  0
                  • H Hamid Taebi

                    I test this code and it work (you need to a resource(bitmap))

                    	TVINSERTSTRUCT	TreeCtrlItem;
                    	CBitmap Bmp;
                    	CImageList *m_ImageList;
                    	HTREEITEM hTreeItem1;
                    	m_ImageList = new CImageList();
                    	m_ImageList->Create(50,50, ILC_COLORDDB,0,0);
                    		Bmp.LoadBitmap(IDB_BITMAP1);//resource bitmap with 5 image on it
                    
                    		m_ImageList->Add(&Bmp,RGB(155,155,155));
                    
                    	TreeCtrlItem.hParent = TVI_ROOT;
                    	TreeCtrlItem.hInsertAfter = TVI_LAST;
                    	TreeCtrlItem.item.mask = TVIF_TEXT |TVIF_IMAGE|TVIF_SELECTEDIMAGE;
                    
                    	TreeCtrlItem.item.pszText = CA2T("(A)");;//if you use from VS2005 instead CA2T use LPTSTR();
                    	TreeCtrlItem.item.lParam = 0;
                    	TreeCtrlItem.item.iImage=0;
                    	TreeCtrlItem.item.iSelectedImage=0;
                    	hTreeItem1 = m_Tree1.InsertItem(&TreeCtrlItem);
                    		m_Tree1.SetImageList(m_ImageList, LVSIL_NORMAL);
                    
                    	TreeCtrlItem.hParent = hTreeItem1;
                    	TreeCtrlItem.item.pszText = CA2T(" (B)");
                    	TreeCtrlItem.item.lParam = 1;
                    	TreeCtrlItem.item.iImage=1;
                    	TreeCtrlItem.item.iSelectedImage=1;
                    	m_Tree1.InsertItem(&TreeCtrlItem);
                    	m_Tree1.SetImageList(m_ImageList, LVSIL_NORMAL);
                    

                    _**


                    **_

                    whitesky


                    A Offline
                    A Offline
                    anu_88
                    wrote on last edited by
                    #9

                    Thank you very much:)

                    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