Setting the Images for an Individual Item

OverviewSample

The different types of images used by the extended combo box item are determined by the values in the iImage, iSelectedImage, and iOverlay members of the structure. Each value is the index of an image in the associated image list of the control. By default, these members are set to 0, causing the control to display no image for the item. If you want to use images for a specific item, you can modify the structure accordingly, either when inserting the combo box item or by modifying an existing combo box item.

Setting the Image for a New Item

If you are inserting a new item, initialize the iImage, iSelectedImage, and iOverlay structure members with the proper values and then insert the item with a call to .

The following example inserts a new extended combo box item (cbi) into the extended combo box control (m_comboEx), supplying indices for all three image states:

COMBOBOXEXITEM     cbi;
CString            str;
int                nItem;

cbi.mask = CBEIF_IMAGE | CBEIF_INDENT | CBEIF_OVERLAY |
     CBEIF_SELECTEDIMAGE | CBEIF_TEXT;

cbi.iItem = i;
str.Format(_T("Item %02d"), i);
cbi.pszText = (LPTSTR)(LPCTSTR)str;
cbi.cchTextMax = str.GetLength();
cbi.iImage = 0;
cbi.iSelectedImage = 1;
cbi.iOverlay = 2;
cbi.iIndent = (i & 0x03);   //Set indentation according
                            //to item position

nItem = m_comboEx.InsertItem(&cbi);
ASSERT(nItem == i);

Setting the Image for an Existing Item

If you are modifying an existing item, you need to work with the mask member of a COMBOBOXEXITEM structure.

To modify an existing item to use images

  1. Declare a COMBOBOXEXITEM structure and set the mask data member to the values you are interested in modifying.

  2. Using this structure, make a call to .

  3. Modify the mask, iImage, and iSelectedImage members of the newly returned structure, using the appropriate values.

  4. Make a call to , passing in the modified structure.

The following example demonstrates this procedure by swapping the selected and unselected images of the third extended combo box item:

COMBOBOXEXITEM     cbi;
CString            str;
int                nItem;

cbi.mask = CBEIF_IMAGE | CBEIF_SELECTEDIMAGE;
cbi.iItem = 2;
m_comboEx.GetItem(&cbi);

cbi.iImage = 1;
cbi.iSelectedImage = 0;
nItem = m_comboEx.SetItem(&cbi);
ASSERT(nItem != 0);

See Also   Windows Common Controls and MFC Classes