Late binding of image - I_IMAGECALLBACK | CodeGuru

Late binding of image – I_IMAGECALLBACK

When inserting an item in the list view control, you dont have to specify the image just then. You can delay a decision on the image by using a callback item. A callback item is an item that causes the list view control to send the LVN_GETDISPINFO notification to its parent whenever it needs information […]

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

When inserting an item in the list view control, you dont


have to specify the image just then. You can delay a decision on the image


by using a callback item. A callback item is an item that causes the list


view control to send the LVN_GETDISPINFO notification to its parent whenever


it needs information to display the item. The LVN_GETDISPINFO notification


can be handled by the parent window or it can be reflected back to the


list view control, the latter solution being the more preferred. Here are


the steps to use message reflection.



 


  • Add a message handler for =LVN_GETDISPINFO in your CListCtrl derived class.
    The = sign indicates that it is a reflected message. This adds a line
    in the message map section which looks like

    ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetDispInfo)


  • Implement the message handler. The message handler shown below does not
    show any logic to decide on the image index. The image index would most
    likely be a function of the item index and/or the items data (pItem->lParam).

    void CMyListCtrl::OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult) 
    { 
            LV_ITEM *pItem = &((LV_DISPINFO*)pNMHDR)->item; 
    
            if( pItem->mask & LVIF_IMAGE ) 
            { 
                    // GetImageFor() needs to be defined and should return image number 
                    pItem->iImage = GetImageFor( pItem-> iItem); 
            } 
           
            *pResult = 0; 
    }

     


  • Insert items using the I_IMAGECALLBACK value for image index. E.g.
  • m_listctrl.InsertItem( nRow, sItemText, I_IMAGECALLBACK );

 
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.