tags:

views:

100

answers:

2

I have a WTL application that uses an extended combobox control (the Win32 class ComboBoxEx32) with the CBS_DROPDOWNLIST style. It works well (I can have images against each item in the box) but the keyboard behaviour is different to a normal combobox - pressing a key will not jump to the first item in the combo that starts with that letter.

For example, if I add the strings 'Arnold', 'Bob' and 'Charlie' to the combo, if I then select the combo and press 'B', then 'Bob' won't be selected.

Does anyone know how to make this work? Currently the only idea I can think of is to somehow subclass the 'actual' combobox (I can get the handle to this using the CBEM_GETCOMBOCONTROL message) and process WM_CHARTOITEM. This is a PITA so I thought I'd ask if anyone else has come across this issue before.

A: 

My suggestion is to ditch CComboBoxEx and draw the icon with an owner-draw regular combo box. CComboBoxEx is slightly different from the 'normal' combobox but in just enough ways that I suspect it's a complete re-implementation. Notice how a selected item looks slightly different from one that is selected in a normal combo box, as well.

Owner draw controls in WTL are quite easy to implement with the COwnerDraw mixin.

Not an answer to your question, just letting you know that that's how I deal CComboBoxEx nowadays :)

Roel
+1  A: 

In the end I hooked the combobox control (obtained with CBEM_GETCOMBOCONTROL) and trapped the WM_CHARTOITEM message and performed my own lookup. I can post code if anyone else is interested.

Rob