About ComboBoxEx Controls
ComboBoxEx controls are combo box controls that provide native support for item images. To make item images easily accessible, the control provides image list support. By using this control, you can provide the functionality of a combo box without having to manually draw item graphics.
This topic contains the following sections.
- Creating ComboBoxEx Controls
- ComboBoxEx Control Styles
- ComboBoxEx Control Items
- Callback Items
- ComboBoxEx Control Image Lists
- About ComboBoxEx Control Notification Messages
- ComboBoxEx Control Message Forwarding
Creating ComboBoxEx Controls
Effectively, a ComboBoxEx control creates a child combo box and performs owner draw tasks for you based on an assigned image list. Therefore, the CBS_OWNERDRAWFIXED style is implied and it's not necessary to use it when creating the control. Because image lists are used to provide item graphics, the CBS_OWNERDRAWVARIABLE style cannot be used.
You can create a ComboBoxEx control by using the CreateWindowEx function and specifying WC_COMBOBOXEX as the window class. The class is registered when the InitCommonControlsEx function is called as explained above.
ComboBoxEx controls are created without a default image list. To use item images, you must create an image list for the ComboBoxEx control and assign it to the control using the CBEM_SETIMAGELIST message. If you do not assign an image list to the ComboBoxEx control, the control displays item text only.
ComboBoxEx Control Styles
ComboBoxEx controls support only the following ComboBox styles:
There are also several ComboBoxEx Control Extended Styles that are used only by ComboBoxEx.
The CBS_SIMPLE style may not work properly in some cases.
Because the ComboBoxEx control performs owner draw tasks for you based on an assigned image list, the CBS_OWNERDRAWFIXED style is implied; you need not use it when creating the control. Because image lists are used to provide item graphics, the CBS_OWNERDRAWVARIABLE style cannot be used. The ComboBoxEx control also supports ComboBoxEx Control Extended Styles that provide additional features.
ComboBoxEx Control Items
ComboBoxEx controls maintain item information using a COMBOBOXEXITEM structure. This structure includes members for item indexes, image indexes (normal, selection state, and overlay), indentation values, text strings, and item-specific values.
The ComboBoxEx control provides easy access to and manipulation of items through messaging. To add or delete an item, send the CBEM_INSERTITEM or CBEM_DELETEITEM message. You can modify items currently in the control using the CBEM_SETITEM message.
ComboBoxEx controls support callback item attributes. You can specify an item as a callback item when you add it to the control using CBEM_INSERTITEM. When you assign values to an item's COMBOBOXEXITEM structure, you must specify the appropriate callback flag values. The following are COMBOBOXEXITEM structure members and their corresponding callback flag values.
The control will request information about callback items by sending CBEN_GETDISPINFO notification codes. This notification is sent in the form of a WM_NOTIFY message. When your application processes this message, it must provide the requested information for the control. If you set the mask member of the accompanying COMBOBOXEXITEM structure to CBEIF_DI_SETITEM, the control will store the item data and will not request it again.
ComboBoxEx Control Image Lists
If you want a ComboBoxEx control to display icons with items, you must provide an image list. ComboBoxEx controls support up to three images for an item—one for its selected state, one for its nonselected state, and one for an overlay image. Assign an existing image list to a ComboBoxEx control using the CBEM_SETIMAGELIST message.
The COMBOBOXEXITEM structure contains members that represent the image indexes for each image list (selected, unselected, and overlay). For each item, set these members to display the desired images. It is not necessary to specify image indexes for each type of image. You can mix and match image types as you like, but always set the mask member of the COMBOBOXEXITEM structure to indicate which members are being used. The control ignores members that have not been flagged as valid.
If you use the CBS_SIMPLE style, icons are not displayed.
About ComboBoxEx Control Notification Messages
A ComboBoxEx control sends notification messages to report changes within itself or to request callback item information. The parent of the control receives all WM_COMMAND messages from the combo box contained within the ComboBoxEx control. The ComboBoxEx control sends its own notifications using WM_NOTIFY messages. As a result, the control's owner must be prepared to process both forms of notification messages.
Following are the ComboBoxEx-specific notification codes that are sent through WM_NOTIFY messages.
|CBEN_BEGINEDIT||Signals that the user has activated the drop-down list or clicked in the control's edit box.|
|CBEN_ENDEDIT||Signals that the user has selected an item from the drop-down list or has concluded an edit operation within the edit box.|
|CBEN_DELETEITEM||Reports that an item was deleted.|
|CBEN_GETDISPINFO||Requests information about an item's attributes.|
|CBEN_INSERTITEM||Signals that an item was inserted in the control.|
ComboBoxEx Control Message Forwarding
The following are the standard combo box messages that a ComboBoxEx control forwards to its child combo box. Some of these messages may be processed by the ComboBoxEx control either before or after the message has been forwarded.
Following are the windows messages that a ComboBoxEx control forwards to its parent window: