CIconListBox - A list box with Icons

Environment: Windows NT4 SP4, Visual C++ 6


I needed a listbox showing Icons and text strings in our Application. When I didn't find any, I decided to create one. This List Box supports changing Icon for an item and removing the ImageList for the List Box at runtime.

How To Use It

To use this listbox class, simply drag a list box from the controls palette and drop it in the dialog Box. Set the properties Owner Draw style to Fixed or Variable, and with the Has Strings style checked.

Following are the steps to add a CIconListBox Class to a dialog:

  • Add IconListBox.cpp and IconListBox.h to your project.
  • Add include "IconListBox.h" to the header file of your dialog class.
  • Use ClassWizard to add a member variable of control type for the List Box. Then replace the CListbox type with CIconListBox.

// in dialog.h
CIconListBox	m_ListBox;

To set the ImageList, item text and/or Image, the overloaded public methods of CIconListBox Class are used:

int AddString(LPCTSTR lpszItem);
int AddString(LPCTSTR lpszItem, int iImg);
int InsertString(int iIndex, LPCTSTR lpszItem);
int InsertString(int iIndex, LPCTSTR lpszItem, int iImg);
void SetItemImage(int iIndex, int iImg);
inline void SetImageList(CImageList* pImgList = NULL)
{ m_pImageList = pImgList; }

In the demo application the Image list is set to List Box in the dialog's OnInitDialog() function. InitImageLists() method is the Dialog class function which is used to create the Image List.

// TODO: Add extra initialization here


Download demo project - 24 Kb
Download source - 3 Kb


  • Set-/GetItemData() needs to be overwritten

    Posted by Legacy on 01/30/2003 12:00am

    Originally posted by: Kurt Santel�

    This "tuned" listbox works great, except if you have already used the function SetItemData() for another purpose. Catching this function, and overwriting it would solve the problem. Or another way of storing which icon needs to be displayed is another solution.


  • Thanks Sekhar

    Posted by Legacy on 11/11/2002 12:00am

    Originally posted by: Mash

    Was looking for implementing icons in the listbox.
    This serves my purpose perfect.

  • Is it possible to use it in WinCE?

    Posted by Legacy on 08/05/2002 12:00am

    Originally posted by: Peter

    Hi. I'm trying to use the class in application written in eMbedded Visual C++. Will it work? If it will, what should I add and where?
    Thanks in advance

  • how to do it in sdk

    Posted by Legacy on 02/17/2002 12:00am

    Originally posted by: deepak

    It's good in MFC.
    But if I want to implement it in SDK?
    How to do it?

  • Problem I used it but my first item in listbox does not display the right color?

    Posted by Legacy on 02/01/2002 12:00am

    Originally posted by: Mahshid

    Hi, Thanks for the code. i followed the instruction in this page to add the Listbox, My first item in the list always display my third item in the list and it is not correct. Does anybody know what my mistake is?

  • Nice! One Change...

    Posted by Legacy on 10/16/2001 12:00am

    Originally posted by: Chris Adamson

    In the method:

    void CIconListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

    << snip >>
    I changed the code so that it draws the text next to the various sized bitmaps (instead of hard coding 16 pixels).
    << snip >>

    IMAGEINFO inf;
    VERIFY(m_pImageList->GetImageInfo(0, &inf));
    rClient.left += inf.rcImage.right;
    rText.left += inf.rcImage.right + 2; += 2;

    Other than that, thanks for the class!
    Chris Adamson

  • Ex(Properties)List

    Posted by Legacy on 10/07/2001 12:00am

    Originally posted by: Mike Philis

    Do you need an advanced list control? Check this out:


  • MultiSelect -> SelItemRange -> Disaster!!

    Posted by Legacy on 09/20/2001 12:00am

    Originally posted by: Raj

    Excellent work!!
    I'd like to point out a problem with your Iconic listbox.
    1. List box style is made "Multiple" or "Extended"
    2. Add a check box or any other toggle control to your dialog.
    3. In the BN_CLICKED event of the above control, add the following code:
    void CIconLBDemoDlg::OnCheck1()
    int state = ((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck();
    CListBox* pListBox = (CListBox*)GetDlgItem(IDC_ICONLISTBOX);
    pListBox->SelItemRange(state, 0, 5);

    The bk color of the list box remains blue.. when we use SelItemRange.


  • A free tool to rename an Existing Visual Studio project.

    Posted by Legacy on 09/07/2001 12:00am

    Originally posted by: Steven

    UCanCode Just release a new version of toolbox,you can use it to rename an existing visual studio project or to backup an existing visual studio a free copy by visit

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Hundreds of millions of users have adopted public cloud storage solutions to satisfy their Private Online File Sharing and Collaboration (OFS) needs. With new headlines on cloud privacy issues appearing almost daily, the need to explore private alternatives has never been stronger. Join ESG Senior Analyst Terri McClure and Connected Data in this on-demand webinar to take a look at the business drivers behind OFS adoption, how organizations can benefit from on-premise deployments, and emerging private OFS …

Most Popular Programming Stories

More for Developers

RSS Feeds