Using overlay images | CodeGuru

Using overlay images

The tree view in conjunction with the image list allows upto four overlay images. Overlay images are images that are drawn transparently over another image. The overlay images are supported only for the item images and not for the state images. Unlike what the documentation says, you can choose any image in the image list […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More




The tree view in conjunction with the image list allows upto four overlay


images. Overlay images are images that are drawn transparently over another


image. The overlay images are supported only for the item images and not


for the state images. Unlike what the documentation says, you can choose


any image in the image list to serve as an overlay image it need not


be among the first 15.



 


Step 1: Set up the overlay images


The image list has to be set up with the overlay images by calling the


function SetOverlayImage(). Upto four images can be added to the list of


overlay images. Call this function for the image list object associated


with the tree view control for the item images. We can call this function


before we associate the image list with the tree view control or after


it does not matter. Normally this code would be clubbed with the code


where you create the image list and associate it with the tree view control.

The SetOverlayImage() takes two arguments. The first argument is the
index of the image within the image list that you want to use as an overlay
mask. If you want the third image in the list to be an overlay mask then
this value would be 2 and if you want the tenth image, this value would
be 9.

The second argument is the one-based index of the overlay mask. This
argument can have a value of 1 to 4 inclusive. This serves as the identifier
for the overlay mask. If you are using only one image as an overlay mask,
you can choose any of the four index it need not be one necessarily.
Also, if you call SetOverlayImage() for two different images with the same
overlay mask index then the latter call will supercede the previous call.

 

        m_tree.m_image.SetOverlayImage(15, 1 );
        m_tree.m_image.SetOverlayImage(16, 2 );
        m_tree.m_image.SetOverlayImage(18, 3 );
        m_tree.m_image.SetOverlayImage(20, 4 );

 


Step 2: Set the item state to use the overlay mask


You can specify the overlay mask when inserting a new item or you can specify


it later by calling SetItemState(). We actually use to the macro INDEXTOOVERLAYMASK()


to specify the overlay mask index.



 
        // Use third overlay mask
        SetItemState( hItem, INDEXTOOVERLAYMASK(3), TVIS_OVERLAYMASK );
        // Remove overlay mask by using index zero.
        SetItemState( hti, INDEXTOOVERLAYMASK(0), TVIS_OVERLAYMASK );

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.