我使用任务管理器查看动态创建的控件,发现每次使用 ImageList 创建 TreeView 时,每次销毁树并再次创建时, GDI 对象计数都会增加 4。但是,ListView 从来没有问题。
我知道状态图像的TVS_CHECKBOXES
问题并且已经破坏了状态图像列表,但我随后实施了:
ImageList_Destroy(TreeView_SetImageList(GetHandle(), nullptr, TVSIL_NORMAL));
现在资源泄漏已经消失了。
到目前为止,您似乎必须手动清理以下图像WM_DESTROY
:
Button_SetImageList() - Have to set it to switch it to `BUTTON_IMAGELIST.himl=BCCL_NOGLYPH` to clear it.
TreeView_SetImageList(LVILS_STATE) - if you set it or used `TVS_CHECKBOXES`
TreeView_SetImageList(LVILS_NORMAL) - if you set it
BM_SETIMAGE and STM_SETIMAGE - destroy your own but also set to NULL and destroy returned handle to get rid of potential hidden bitmap handle if different handle than your own.
但是 ListView 是不同的,是按设计还是我应该继续WM_DESTROY
使用类似的东西:
ImageList_Destroy(ListView_SetImageList(GetHandle(), nullptr, LVSIL_STATE));
ImageList_Destroy(ListView_SetImageList(GetHandle(), nullptr, LVSIL_SMALL));
ImageList_Destroy(ListView_SetImageList(GetHandle(), nullptr, LVSIL_NORMAL));
请注意,使用WM_NCDESTROY
TreeViews 为时已晚。