tags:

views:

198

answers:

2

I want my tree view control to show an item with a folder icon next to it. so, 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, this does not add a folder icon next to my subscription label. it works correctly but doesn't display any image.

A: 

I use 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);
Valentin Galea
I tried this method and it still doesn't work.
Attilah
A: 

instead of using :

bmp.FromHandle(hFolderBitmap);

I had to use :

bmp.Attach(hFolderBitmap);

Attilah