Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I tried to load an image in treeView but it isn't loaded..
C++
HTREEITEM hItem;
CBitmap m_Bitmap1, m_Bitmap2, m_Bitmap3, m_Bitmap4;

m_Bitmap1.LoadBitmap(IDB_BITMAP2);
//m_Bitmap2.LoadBitmap(IDB_BITMAP9);

CImageList* m_ImageListTree;
m_ImageListTree = new CImageList;

m_ImageListTree->Create(16, 16, ILC_COLOR32, 1, 1);
m_ImageListTree->Add(&m_Bitmap1, RGB(255, 0, 255));
m_treeCtrl.SetImageList(m_ImageListTree, LVSIL_SMALL);

hItem = m_treeCtrl.InsertItem(aDir[i],i,i, TVI_ROOT);


What I have tried:

I have an image BMP in resources, but it isn't loaded.
Posted
Updated 25-Jan-22 9:38am
v2
Comments
Richard MacCutchan 25-Jan-22 12:18pm    
What is aDir and what is the value of i?

You better use the debugger to see whether your m_Bitmap1 has loaded the image and check the return codes. If I remember correctly this MFC code is very picky in image format and size.

Are you getting an hItem back?
 
Share this answer
 
Comments
Member 14594285 25-Jan-22 12:11pm    
image is 8 bit and dimension 225 x 225
KarstenK 26-Jan-22 13:08pm    
the picture maybe to big for the small item. Check the return codes!!!
I have modified in code. try the following:
HTREEITEM hItem;
CBitmap m_Bitmap1, m_Bitmap2, m_Bitmap3, m_Bitmap4;

m_Bitmap1.LoadBitmap(IDB_BITMAP1);

CImageList* m_ImageListTree;
m_ImageListTree = new CImageList;
m_ImageListTree->Create(IDB_BITMAP1, 16, 16, RGB(255, 255, 255));
m_ImageListTree->Add(&m_Bitmap1, RGB(255, 0, 255));
m_treeCtrl.SetImageList(m_ImageListTree, LVSIL_SMALL);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900