Initializing the image list


The list view control should be initialized in the OnInitDialog() function of the CDialog or in the OnInitialUpdate() function of the CFormView. A list view control can have up to three image lists associated with it: two of them for icons and the third for state images.

Here are the steps involved

  1. Declare variables of the type CImageList in your CDialog or CFormView sub class.
  2. In the OnInitDialog() or OnInitialUpdate() function call the Create() function for the CImageList member variables.
  3. Call the SetImageList() member function of the list view control.
Here is a sample code.
m_imgIcon.Create( IDB_LARGEICONS, 32, 1, (COLORREF)-1 ); //Create from bitmap resource 
m_listctrl.SetImageList( &m_imgIcon, LVSIL_NORMAL );  //Set the image list 
m_imgIconSmall.Create( IDB_SMALLICONS, 16, 1, (COLORREF)-1 ); 
m_listctrl.SetImageList( &m_imgIconSmall, LVSIL_SMALL );
The image list set using LVSIL_NORMAL is used only for the LVS_ICON mode. For this mode a 32x32 icon is usually used. For all other view modes the image list set with LVSIL_SMALL is used. The standard icon size for this is 16x16 pixels. You do not have to use the standard sizes though. For that matter, you do not have to use square images either, the images can have any aspect you want.
 



Comments

  • Overlay and State Images!!!

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

    Originally posted by: Mustafa Zein

    I found all the examples here deals with the Images/ Icons appears at the Items itself, but none for choosing, setting, displaying, changening the Overlay and State Images at reuntime!!!

    Hope you can cover this soon, thank you

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

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Webinar on September 23, 2014, 2 p.m. ET / 11 a.m. PT Mobile commerce presents an array of opportunities for any business -- from connecting with your customers through mobile apps to enriching operations with mobile enterprise solutions. Join guest speaker, Michael Facemire, Forrester Research, Inc. Principal Analyst, as he discusses the new demands of mobile engagement and how application program interfaces (APIs) play a crucial role. Check out this upcoming webinar to learn about the new set of …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds