Updated WM_CTLCOLOR.. processing so the control renders correctly with an XP Manifest.
Added missing mnubar.bmp to download.
vbAccelerator ComboBoxEx Control
A full implementation of the ComCtl32 ComboBoxEx Control directly from the API with Owner Draw FeaturesThis article presents an implementation of the Common Controls ComboBoxEx control from scratch in Visual Basic. Although this control is available with some versions of VB, this version provides a number of enhancements including pre-built styles (drive picking, font picking, colour picking) and helper such as auto-completion. And you get the full source code to play around with!
The interface to the ComboBoxEx control is very similar to the VB ComboBox control. Standard methods such as AddItem, Clear, ListCount, List, ItemData and so on are all supported in exactly the same way as for the VB control. The ComboBoxEx control also allows you to associated up to two icons with each ListItem from an ImageList, and this version also allows you complete control over drawing your own ListItems using Owner Draw styles.
To add icons, first set the ImageList property. The ImageList passed in must be a ComCtl32.DLL compatible image list, which means that you can either use a VB5 ComCtl32.OCX ImageList or any of the vbAccelerator ImageLists (such as the vbAccelerator ImageList Control, ImageList Class and System ImageList class). Unfortunately the VB6 MSComCtl.OCX ImageList is not compatible with ComCtl32.DLL and hence won't work. There is a workaround for this, but it isn't pretty. You basically need to copy all of the images from the MSComCtl.OCX image list into a vbAccelerator ImageList class.
Once you've configured an appropriate the ImageList, use the ItemIcon or ItemIconSelected properties to associate the image with your control. These properties accept and return a zero-based index to the icon within the ImageList. If you don't set the ItemIconSelected property, then the ItemIcon will still be used when the item is selected.
There are three properties for controlling the style of the control:
The Style property is the same as the standard VB ComboBox one, so the other styles are covered next:
This property allows you to set or remove the three extended properties provided by the ComboBoxEx control at design-time or run-time:
This property changes the style the control uses to draws, at design-time or at run-time. There are 9 pre-built styles:
Other Properties and Methods
The ComboBoxEx control is a simple way of adding icon ComboBoxes to your application, and makes life particularly easy if you want to implement a Drive, Font or Colour picker. If you are prepared to delve into the GDI world, you can also create your own completely customised ComboBox controls, although note that you cannot modify the height of an item in the ComboBox. To achieve combo box items with variable heights, you need to use a standard ComboBox control with Owner-Draw mode set - see the vbAccelerator OwnerDraw Combo and ListBox Control for details of how to achieve this.