How to use CImageList
I want my tree view control to show an item with a folder icon next to it. therefore, I wrote this piece of code:
HBITMAP hFolderBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),_T("info.bmp"),IMAGE_BITMAP,20,20,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(hFolderBitmap)
{
cil.Create(20,20,ILC_COLOR32,0,5);
bmp.FromHandle(hFolderBitmap);
cil.Add(&bmp,RGB(255,0,255));
}
GetTreeCtrl().SetImageList(&cil,TVSIL_NORMAL);
hrootFolder = GetTreeCtrl().InsertItem(_T("Subscriptions"),0,0,TVI_ROOT);
but that doesn't add the folder icon next to my signature. it works correctly but doesn't display the image.
0
a source to share
2 answers
I am using this:
UINT uiBmpId = theApp.m_bHiColorIcons ?
IDB_MACROBROWSE_IMGLIST_HQ : IDB_MACROBROWSE_IMGLIST;
CBitmap bmp;
if( !bmp.LoadBitmap( uiBmpId ) )
{
ASSERT( FALSE );
return;
}
BITMAP bmpObj;
bmp.GetBitmap (&bmpObj);
UINT nFlags = ILC_MASK;
nFlags |= (theApp.m_bHiColorIcons) ? ILC_COLOR24 : ILC_COLOR4;
m_imageList.Create( 16, bmpObj.bmHeight, nFlags, 0, 0 );
m_imageList.Add( &bmp, RGB (255, 0, 255) );
GetTreeCtrl().SetImageList (&m_imageList, TVSIL_NORMAL);
0
a source to share