MFC using an ImageList in a TreeView control
This is a bit of a departure for my regular blogging but I've been working in MFC lately so I'm posting some of the things I've learned. So I have a tree view control that I want to add some images to. In .net this is easy just drop in an ImageList and add the images in the designer. In MFC this takes a wee bit more work.
Here is the actual code:
m_ImageList a CImageList member variable.
m_treeGFM is a member variable mapped to my tree view control.
The icons are resources I have added to my application.
For more on the CImageList class head over to MSDN and read about it.
Here is the actual code:
/* create the image list with 16x16 sized icons,
32 bit color, 0 images to start, and resize the array 1 at a time when adding
new images*/
m_ImageList.Create(16,16,ILC_COLOR32,0,1);
m_ImageList.Add( AfxGetApp()->LoadIcon(IDI_ICON_ORG) );
m_ImageList.Add( AfxGetApp()->LoadIcon(IDI_ICON_POSITION) );
// set theimage list to be used in the tree view control with normal sized icons
m_treeGFM.SetImageList( &m_ImageList, LVSIL_NORMAL );
m_ImageList a CImageList member variable.
m_treeGFM is a member variable mapped to my tree view control.
The icons are resources I have added to my application.
For more on the CImageList class head over to MSDN and read about it.
Comments
Can you post a sample code for various icons for each tree view items?
Pandi
http://computerprogramminghelp.blogspot.com
gkpandi07.wings@gmail.com