3

I have a TreeView control in a Windows C++ application that has an ImageList set.
I am trying to insert an node that does not have icon (without TVIF_IMAGE flag) but the icon is still displayed.

    TVINSERTSTRUCT tvis = { 0 };
    tvis.hParent = hParent;
    tvis.hInsertAfter = hInsertAfter;
    tvis.item.mask = TVIF_TEXT;
    tvis.item.pszText = (LPTSTR) lpszItem;
    tvis.item.iImage = 0;
    tvis.item.iSelectedImage = 0;
    tvis.item.state = nState;
    tvis.item.stateMask = nStateMask;
    tvis.item.lParam = lParam;
    ::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);

Is that possible/ supported ?

vlg789
  • 751
  • 6
  • 20

2 Answers2

3

The thing is you are inserting an item with [default] image 0. You not only need -1, but you also need TVIF_IMAGE:

    tvis.item.mask = TVIF_TEXT | TVIF_IMAGE;
    tvis.item.iImage = -1;

Here is the effect of this change compared you your snippet (source code):

enter image description here

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Doesn't work. It worked for you ? I am asking because I want to know if is smth related to styles or so – vlg789 Feb 17 '14 at 15:58
2

Try setting the image flag to -1 rather than 0;

rrirower
  • 4,338
  • 4
  • 27
  • 45