
I needed a
list box
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.
enum { IDD = IDD_ICONLBDEMO_DIALOG };
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.
InitImageLists();
m_ListBox.SetImageList(&m_imgNormal);
Downloads
Download demo project -
24 Kb
Download source - 3 Kb