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 COMBOBOXEXITEM 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.
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 CComboBoxEx::InsertItem.
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);
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
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);