Treeviews Share Image Lists by Default

Last reviewed: September 29, 1995
Article ID: Q131287
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT version 3.51
        - Microsoft Windows 95 version 4.0
        - Microsoft Win32s version 1.3
    

SUMMARY

The LVS_SHAREIMAGELISTS style is available for listview controls to enable the same image lists to be used with multiple listview controls. There is no equivalent TVS_SHAREIMAGELISTS, however, for the treeview control because treeviews share image lists by default.

MORE INFORMATION

By default, a listview control takes ownership of the image lists associated with it. For listviews, this could be any of three image lists (those with large icons, small icons, or state images). These three image lists are set by calling ListView_SetImageList() with the flags LVSIL_NORMAL, LVSIL_SMALL, or LVSIL_STATE respectively. The listview then takes responsibility for destroying these image lists when it is destroyed.

Setting the LVS_SHAREIMAGELISTS style, however, moves ownership of the image lists from the listview control to the application. Because this style assumes that the image lists are shared by multiple listviews, specifying this style requires that the application destroy the image lists when the last listview using them is destroyed. Failure to do so causes a memory leak in the system.

Similarly, because treeviews share image lists by default, an application that associates an image list with a treeview should ensure that the image list is destroyed after the last treeview using it is destroyed. Another way to do this is to first set the treeview's image list to NULL by using TreeView_SetImageList(); then destroy the handle to the previous image list returned by the function.


Additional reference words: 1.30 4.00 95 Common Controls
KBCategory: kbui
KBSubcategory: UsrCtl


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.