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 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 );


More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read