CTreeCtrl::ModifyStyle시 GDI개체 증가 되는 문제 MFC。

ModifyStyle로 TVS_CHECKBOXES 를 사용한다고 체크하는 경우,
ImageList가 생성되어 4개의 GDI Object를 생성한다.
이는 사용자가 반드시 사용후에 삭제해 주어야 한다.

Ex>
CImageList* pImgList = NULL;

pImgList = m_ProdTypeTree.GetImageList(TVSIL_STATE);
if( pImgList )
pImgList->DeleteImageList();
------------------------------------------------------------------------------------------------------------------------

I don't have a GDI leak detector but testing with task manager, I get:
 
// Adds 4 GDI Objects
m_TreeCtl.ModifyStyle(0, TVS_CHECKBOXES);
...
...
// Removes 4 GDI Objects
HIMAGELIST hImgList = TreeView_SetImageList(m_TreeCtl.GetSafeHwnd(), NULL, TVSIL_STATE);
if (hImgList)
ImageList_Destroy(hImgList);
 
I can't find any info documenting a leak.

------------------------------------------------------------------------------------------------------------------------
ConstantDescription
TVS_CHECKBOXES

Version 4.70. Enables check boxes for items in a tree-view control. A check box is displayed only if an image is associated with the item. When set to this style, the control effectively uses DrawFrameControl to create and set a state image list containing two images. State image 1 is the unchecked box and state image 2 is the checked box. Setting the state image to zero removes the check box altogether. For more information, see Working with state image indexes.

Version 5.80. Displays a check box even if no image is associated with the item.

Once a tree-view control is created with this style, the style cannot be removed. Instead, you must destroy the control and create a new one in its place. Destroying the tree-view control does not destroy the check box state image list. You must destroy it explicitly. Get the handle to the state image list by sending the tree-view control aTVM_GETIMAGELIST message. Then destroy the image list with ImageList_Destroy.

If you want to use this style, you must set the TVS_CHECKBOXES style withSetWindowLong after you create the treeview control, and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues.

------------------------------------------------------------------------------------------------------------------------

덧글

댓글 입력 영역