Typing Aid ComboBox


The current MFC combobox class is insufficient. The pop-down choicelists provided for the
application I was writing needed to reduce the amount of typing a user must do.
The user is given a list of items from which they can choose any combination of
selections. When a selection is chosen from the list, it is placed into the
field. This also helps to reduce the amount of spelling errors which can occur.
Implementation Specfication This combo box will consist of an edit field with a
pop down choicelist. The user can show the choicelist by left-clicking on the
down-arrow button or by pressing alt- down or by pressing alt-up. The user can
hide the choicelist by clicking in the field or by pressing alt-down or by
pressing alt-up. By default, the choicelist is not shown when the field
receives focus (eg, mouse click on the field).

When the user types, the field will automatically complete the typing if the
substring typed matches the beginning of an item in the choicelist. The
selection is completed by the user, if the user hits the right arrow key, or
the end key, or types a space and that space is not contained within an item
in the choicelist.

The field is subdivided into sections. Each section is delimited by a space.
Each section can be autocompleted. There are 2 forms of autocompletion: when
typing the first match in the choicelist appears in the field; or after typing
some substring (or empty substring) the user can pop-down the choicelist to
show only items which match that substring. The choicelist is reset, such that
all choices will appear in the next section, when the completion finishes.

Any leading spaces will be removed from the completion match.

The key breakdown is:

right arrow, end key – finish autocompletion

spacebar – finish autocompletion only if space is not contained as part of a
substring match

alt-down or alt-up or left-click button – show list of available choices

alt-down or alt-up or left-click in choicelist – hide choicelist, placing
selection in field

left-click in field – hide choicelist if shown, cancelling selection

Enforced choicelists are supported. The behavior of an enforced choicelist
changes so that the user can not type a value which is not an item in the
choicelist. Also, the user can not delete single characters. If the user wishes
to change a selection, the old selection must first be deleted, then the new
selection can be made.


A popup window with a list control as a child are attached to an edit control.
A window with a pseudo-button is wrapped around the edit control to provide
combobox-like functionality.

The edit control is modeled in similar style to MFC. However, I do not use
Windows messages to provide functionality. Therefore, you can not assume
that the following will work.


In the future, I will try to make this functionality available.

The edit control (as does the list control) derives from the respective MFC
control as well as CSharedCtrlAttribs. This class is there to provide the
ability to change the color of a control.

Please consult the .h files as an API reference.

Known Bugs


Example Usage

Here’s an example of creating a dynamic combo box.

BOOL CTypingAidDemoDlg::OnInitDialog()
// Usual Dialog Stuff here …

// Create the combo box
m_pdynCombo = new CTypingAidCombo(TAES_HASLIST);
m_pdynCombo->Create(CRect(100, 30, 200, 25),

// Set the colors
CTypingAidEdit* pEdit = m_ppdynCombo[i]->GetEdit();
pEdit->SetTextColor(RGB(255, 0, 0));
pEdit->SetBkColor(RGB(0, 255, 255));

// Add some columns and items
CListCtrl* pListCtrl = m_ppdynCombo[i]->GetListCtrl();
pListCtrl->InsertColumn(0, “From”, LVCFMT_LEFT, 100);
pListCtrl->InsertColumn(1, “Import Value”, LVCFMT_LEFT, 100);
::ZeroMemory(&lvi, sizeof(lvi));
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 0;

lvi.pszText = “Hello1”;
lvi.pszText = “Hello 2”;

pListCtrl->SetItemText(0, 1, “Apples”);
pListCtrl->SetItemText(1, 1, “oranges”);

// …


Download source – 24 Kb
Download demo project – 36 Kb

More by Author

Must Read