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

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

Most Popular Programming Stories

More for Developers

RSS Feeds

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