Jump to content

ImageList in TreeViewCtrl


Recommended Posts

Guest chris sjak
Posted

I have a TreeView in my program it's implemented using wtl (CTreeViewCtrl). It works fine, but now I want to associate an ImageList to it. I have tried different approaches but none of them have worked.

The goal is to have a picture (16x16 pixels) left of the item.

I have added a bitmap in the resource editor containing the picture.

The first method is where i have declared the data variable m_ImageList as a public HIMAGELIST structure:

// From header file


HIMAGELIST m_ImageList;
Then I use the folowing code to add the imagelist:
m_ImageList=ImageList_Create(16,16,ILC_COLOR,2,10);




	HBITMAP hBitMap;                                     // bitmap handler


	hBitMap =LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP3)); // load the picture from the resource


  


	ImageList_Add(m_ImageList, hBitMap, NULL);






	DeleteObject(hBitMap);




	SendMessage(m_hWnd,TVM_SETIMAGELIST,0,(LPARAM)m_ImageList);
The other approach I've tried is by using CImageList instead of HIMAGELIST. Then I use this code:
m_ImageList.Create( IDB_BITMAP3, 16, 1, RGB(255,255,255) );


    m_TV.SetImageList(m_ImageList, TVSIL_NORMAL );
I declare my TreeView like this:
m_TV.Create( m_hWnd, rect, NULL,


	WS_CHILD | WS_VISIBLE | TVS_HASBUTTONS | TVS_HASLINES,


	WS_EX_CLIENTEDGE,(HMENU)IDC_TREE1);






	TCHAR *Tekst = L"Hejsa";


	TV_INSERTSTRUCT InsertItem;


	HTREEITEM spv1;






  InsertItem.item.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;


        InsertItem.item.pszText = Tekst;


        InsertItem.item.cchTextMax = 15;


        InsertItem.hParent = NULL;


        InsertItem.hInsertAfter = TVI_SORT;


  InsertItem.item.iImage=0;


  InsertItem.item.iSelectedImage=1;




        spv1 = m_TV.InsertItem(&InsertItem);

It shows the text, but not the image... Any idea what the problem is??

regards,

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.