Initializing the image list | CodeGuru

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 Declare variables of […]

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

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 32

×

32 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 16

×

16 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.



 
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.