如何隐藏Windows Treeview控件节点的图标?

时间:2014-08-20 09:16:34

标签: winapi treeview

示例代码:

HIMAGELIST himl;  // handle to image list 
HBITMAP hbmp;     // handle to bitmap 

// Create the image list. 
if ((himl = ImageList_Create(16, 16,
    ILC_COLOR32, 1, 0)) == NULL)
    return ;

// Add the open file, closed file, and document bitmaps. 
hbmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDI_FOLDER));
if (-1 == ImageList_Add(himl, hbmp, (HBITMAP)NULL))
    return;
DeleteObject(hbmp);
if (ImageList_GetImageCount(himl) < 1)
    return;

// Associate the image list with the tree-view control. 
TreeView_SetImageList(hTree, himl, TVSIL_NORMAL);

//init normal books
tvs.hInsertAfter = NULL;
tvs.hParent = TVI_ROOT;
tvs.item.pszText = L"Notebook";
tvs.item.mask = TVIF_TEXT;
HTREEITEM rootItem = TreeView_InsertItem(hTree, &tvs);

问题是:我没有设置TVIF_IMAGETVIF_SELECTEDIMAGE掩码,但结果树视图仍然包含如下图标:

incorrect treeview result

我怎么能隐藏这个图标?

1 个答案:

答案 0 :(得分:0)

它显示文件夹,因为您添加的文件夹图标位于图像列表中的位置0,当您创建TVINSERTSTRUCT以添加项目时,所有值都将重置为0.

如果您不希望它显示图标a)将图标移动到位置1或b)将图像索引设置为位图的大小+ 1;

相关问题