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



Comments

  • very good

    Posted by lingsnow on 06/19/2006 05:50am

    very good

    Reply
  • How to Simultaneously associate two imagelists with a tree control

    Posted by Legacy on 04/12/2001 12:00am

    Originally posted by: Dan Foster

    Your example shows two image lists, but doesn't explain how to accomplish this.

    Please give instructions on how to show two images next to the tree control.

    If you send me your email, I can draw an example of this in microsoft paint for what I need.

    Thank you,
    Dan Foster

    Reply
  • More again on "Using Overlay Images"

    Posted by Legacy on 10/19/2000 12:00am

    Originally posted by: Shayne Kennedy

    Also, if using CListCtrl make sure you allow the setting of the state member of your LV_ITEM structure with LVIF_STATE.
    
    

    Here's a code fragment that worked for me.

    // add overlay image to control's image list
    CImageList* imageList = GetImageList();
    imageList->SetOverlayImage(1, 1);

    // setup the primary image
    LV_ITEM m_lvi.mask;
    m_lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_STATE;
    m_lvi.iItem = listItemRow;
    m_lvi.iSubItem = 0;
    m_lvi.iImage = 0; // the primary image

    // add the overlay
    m_lvi.stateMask = LVIS_OVERLAYMASK;
    m_lvi.state = INDEXTOOVERLAYMASK(1);
    SetItemState( position, &m_lvi);

    Reply
  • more on "Using overlay images"

    Posted by Legacy on 07/18/1999 12:00am

    Originally posted by: Jeff Lehmer


    or if you create your bitmap with this "Create()" you can specify what color in your bitmap will be made transparent:


    // using white for the overlay mask color to ignore
    m_ctlImage.Create(IDB_TREEVIEW,16,0,RGB(255,255,255));


    Reply
  • Using overlay images

    Posted by Legacy on 10/27/1998 12:00am

    Originally posted by: Jeff Lundgren

    Make sure you use the ILC_MASK flag when creating the imagelist
    
    

    Like this:
    m_ImageList.Create(16, 16, ILC_COLOR4 | ILC_MASK, 0, 1);


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Download this IDC report to learn how your organization can benefit from new flash architecture built for the cloud era. The IDC report examines the evolving primary flash array market with a particular emphasis on how next generation flash–driven enterprise storage architectures will take performance, scalability and infrastructure density to the next level.

  • Whether you're wondering if the title of "developer" should have your name next to it or you've just started on the path to software success, consider this guide your personal README.md file. (And if that reference didn't make sense to you, read on. It will soon, grasshopper.) This software developer resource guide explores just how in-demand developers are and the growing gap of qualified individuals needed, discusses the many benefits and perks of being a developer, and enlightens you on the myriad of …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date