COXImageListBox Overview
Copyright © The Code Project 1997-1999, All Rights Reserved

COXImageListBox is CListBox derived class designed to display multiple images of the same size. Images are displayed in multiple columns and if they don't fit the size of the control's window COXImageListBox will automatically support the scrolling in horizontal direction.

COXImageListBox control supports only single selection and the following styles must be specified: LBS_OWNERDRAWFIXED and LBS_MULTICOLUMN; and these styles must not be specified: LBS_MULTIPLESEL and LBS_OWNERDRAWVARIABLE. 

COXImageListBox uses internally an object of CImageList class as a storage for displayed images and uses its functionality to draw them. The number of items in this image list is always the same as the number of items in the list box. And an index of the item in the list box corresponds to the same index of the displayed image in the internal image list. That means that any displayed image can be accessed just by its index.

All CListBox functions can be applied to the COXImageListBox object keeping in mind the limitations on the used styles (e.g. functions for a list box with multiple selection are not applicable).

Usage

In order to use COXImageListBox object in your application you have to create it using standard CListBox::Create() function or subclass the existing list box control, e.g. using DDX/DDV technology for a dialog or a form views. 

After control was successfully created or subclassed you might want to populate it with images that will be displayed in it. We provide many ways of doing this.

First of all you can specify your own external image list object as source of images. Call the following function in order to do that:
int SetImageList(CImageList* pImageList);

You also can add new images to the existing ones through calling the following functions:
int AddImage(CBitmap* pbmImage, CBitmap* pbmMask);
int AddImage(CBitmap* pbmImage, COLORREF crMask);
int AddImage(HICON hIcon);

And you can add a set of images by calling:
int AddImageList(CImageList* pImageList);
function.

We would like to bring your attention to one specific way of populating the image list box with new images. It is known that icons that reside in executable files can be retrieved using Win32 API functions. We provide an automatic way of retrieving icons from executables and insert them in the list box. In order to do that you just have to call the following function:
BOOL LoadIconsFromFile(LPCTSTR lpszFileName=NULL, BOOL bSmallIcon=TRUE);

At any time you can replace any displayed image with another one if you call the following functions:
BOOL ReplaceImage(int nImage, CBitmap* pbmImage, CBitmap* pbmMask=NULL);
BOOL ReplaceImage(int nImage, HICON hIcon);

Note that after you are done with replacing images you have to call RedrawWindow() function in order to update the displayed images.

And, finally, you can remove any displayed image from the list box using:
BOOL RemoveImage(int nImage);

All displayed images can be removed at once using:
void EmptyImageList();
function.

The information about images can be accessed at any time by means of set of the following functions:
BOOL GetImageInfo(int nImage, IMAGEINFO* pImageInfo) const;
HICON GetIcon(int nImage);
HICON GetSelectedIcon();

The internal image list object can be accessed directly through calling:
CImageList* GetImageList();

As an additional functionality we support an option to set the list box background color. Use these functions in order to set/retrieve the control's background color:
virtual COLORREF GetBkColor() const;
void SetBkColor(COLORREF clrBackground); 
 
The sample that demonstrates COXImageListBox class is called ImageListBox and can be found in the .\Samples\gui\ImageListBox subdirectory of your Ultimate Toolbox directory. 
 
Dependency:
#include "OXImageListBox.h"

Source code files:
"OXImageListBox.cpp"