Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I don't understand why when I click on a item of treeView icon changes;
my code to set icon:



CBitmap cBmp, cBmp_hot;
	HIMAGELIST hList, hListHot;
	CImageList *m_imageListGUI;
	m_imageListGUI = new CImageList;

	hList = ImageList_Create(40, 36, ILC_COLOR24 | ILC_MASK, 2, 1);

	m_imageListGUI->Attach(hList);

	cBmp.LoadBitmap(IDB_BITMAP1);
	m_imageListGUI->Add(&cBmp, RGB(0, 0, 0));// Maschera bianca

	m_treeCtrl.SetImageList(m_imageListGUI, 0);

    HTREEITEM hItem;
   //m_treeCtrl.SetIm
   //m_treeCtrl.select
	hItem = m_treeCtrl.InsertItem( _T("ciao"), 0 ,i, TVI_ROOT);


What I have tried:

I tried code that I have written
Posted
Updated 28-Jan-22 5:03am
Comments
Richard MacCutchan 28-Jan-22 10:08am    
You previously posted this question which has now been deleted, where I asked for more information. When you say "when I click on a item of treeView icon changes", what do you mean? Does it change colour, does it change to some other icon or image, does it disappear, etc>? We cannot help unless you tell us exactly what is happening, and why you think it is wrong.
Member 14594285 28-Jan-22 10:11am    
I have a bitmat with 2 images, item has like icon the first image of bitmat, when I click on item second image appears, and the first image disappears, so item chenges his icon, is it clear?
Richard MacCutchan 28-Jan-22 10:36am    
What is the value of the third parameter in your call to m_treeCtrl.InsertItem?
It would appear that you are specifying two images for whether the node is selected or not, So it will change when clicked.
Member 14594285 28-Jan-22 10:41am    
hItem = m_treeCtrl.InsertItem( _T("ciao"), 0 ,i, TVI_ROOT);

i=0;
Richard MacCutchan 28-Jan-22 10:54am    
Sorry, I do not really have any more ideas. The only possibility that I can suggest is that you remove the ILC_MASK option in the call to ImageList_Create, and change the m_imageListGUI->Add call to:
m_imageListGUI->Add(&cBmp);// Maschera bianca

1 solution

I have just had another look at Image List Creation Flags (Shlobj.h) - Win32 apps | Microsoft Docs[^]. The comment for the ILC_MASK flag, states:
Quote:
Use a mask. The image list contains two bitmaps, one of which is a monochrome bitmap used as a mask.

But in your code you have:
C++
m_imageListGUI->Add(&cBmp, RGB(0, 0, 0));

But RGB(0, 0, 0) is a single integer value, not a bitmask.
 
Share this answer
 
Comments
Member 14594285 28-Jan-22 11:08am    
but Add has like second member COLORREF..so if I use RGB i think it's right...I don't know..
Richard MacCutchan 28-Jan-22 11:11am    
OK, I did not see that bit; the documentation is not that easy to follow. Sorry, I am out of ideas.
Member 14594285 28-Jan-22 11:21am    
Ok thanks
Member 14594285 31-Jan-22 9:48am    
I solved, when I used InsertItem hItem = m_treeCtrl.InsertItem( _T("ciao"), 0 ,i, TVI_ROOT); I used i for selectImage and value is 1, so when I clicked image changed, i must be 0

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



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