F
flaviu_
Guest
Hi. It is possible to change the icon of an item in CTreeCtrl depending of his state ? Just like this:
I mean, if the item has collapsed state, then will have an simple folder icon, but he has expanded state, then he will have to change his icon as folder open state, as in attached picture.
I have found something appropriate here:
Setting up state images
but didn't work ...
Here is what I have tried:
void CLeftView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
// TODO: You may populate your TreeView with items by directly accessing
// its tree control through a call to GetTreeCtrl().
m_IL.DeleteImageList();
m_IL.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 4);
m_IL.Add(theApp.LoadIcon(IDI_ROOT));
m_IL.Add(theApp.LoadIcon(IDI_FOLDER));
m_IL.Add(theApp.LoadIcon(IDI_DEFAULT));
m_IL.Add(theApp.LoadIcon(IDI_VEHICLE));
GetTreeCtrl().SetImageList(&m_IL, TVSIL_NORMAL);
m_ILState.DeleteImageList();
m_ILState.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1);
m_ILState.Add(theApp.LoadIcon(IDI_FOLDEROPEN));
GetTreeCtrl().SetImageList(&m_ILState, TVSIL_STATE);
PopulateTree();
}
and
TV_INSERTSTRUCT tv;
tv.hParent = hRoot;
tv.hInsertAfter = TVI_LAST;
tv.item.mask = TVIF_TEXT | TVIF_STATE | TVIS_EXPANDED;
tv.item.stateMask = TVIS_STATEIMAGEMASK;
tv.item.state = INDEXTOSTATEIMAGEMASK(1);
tv.item.pszText = sTemp.GetBuffer();
tv.item.cchTextMax = sTemp.GetLength();
hLevel1 = Tree.InsertItem(&tv);
sTemp.ReleaseBuffer();
Tree.SetItemState(hLevel1, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK);
Here is the sample project: Test project
Could you guide me in order to solve this problem ? Thank you.
Continue reading...
I mean, if the item has collapsed state, then will have an simple folder icon, but he has expanded state, then he will have to change his icon as folder open state, as in attached picture.
I have found something appropriate here:
Setting up state images
but didn't work ...
Here is what I have tried:
void CLeftView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
// TODO: You may populate your TreeView with items by directly accessing
// its tree control through a call to GetTreeCtrl().
m_IL.DeleteImageList();
m_IL.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 4);
m_IL.Add(theApp.LoadIcon(IDI_ROOT));
m_IL.Add(theApp.LoadIcon(IDI_FOLDER));
m_IL.Add(theApp.LoadIcon(IDI_DEFAULT));
m_IL.Add(theApp.LoadIcon(IDI_VEHICLE));
GetTreeCtrl().SetImageList(&m_IL, TVSIL_NORMAL);
m_ILState.DeleteImageList();
m_ILState.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1);
m_ILState.Add(theApp.LoadIcon(IDI_FOLDEROPEN));
GetTreeCtrl().SetImageList(&m_ILState, TVSIL_STATE);
PopulateTree();
}
and
TV_INSERTSTRUCT tv;
tv.hParent = hRoot;
tv.hInsertAfter = TVI_LAST;
tv.item.mask = TVIF_TEXT | TVIF_STATE | TVIS_EXPANDED;
tv.item.stateMask = TVIS_STATEIMAGEMASK;
tv.item.state = INDEXTOSTATEIMAGEMASK(1);
tv.item.pszText = sTemp.GetBuffer();
tv.item.cchTextMax = sTemp.GetLength();
hLevel1 = Tree.InsertItem(&tv);
sTemp.ReleaseBuffer();
Tree.SetItemState(hLevel1, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK);
Here is the sample project: Test project
Could you guide me in order to solve this problem ? Thank you.
Continue reading...