Enhanced ComboBox with AutoComplete
The SECComboBoxEx class extends MFC’s CComboBoxEx class by providing a type ahead or autocomplete feature. The Address combobox in MS Internet Explorer provides the same functionality. As the user types, the control searches through its list of entries for a match. If the control finds a match to the partial entry, it substitutes the text in the edit control with first matching entry and highlights the characters to the right the caret.
Figure 39 – Example Enhanced Combobox Control
The autocomplete feature also skips ahead when the user types in an entry that includes a regularly repeating delimiter strings sequence, such as the “.” in an IP address or the slash character (/) in an URL.
When the user presses the delimiter key once, the entry appears as follows:
Figure 40 – Example Entry with Repeating Delimiters
When the user presses the delimiter key twice, the entry appears as follows:
When the user presses the delimiter key three times, the entry appears as follows:
The user can always click the button to the right to drop down the list of items as well.
The Enhanced ComboBox Class
The SECComboBoxEx class inherits directly from CComboBoxEx.
Figure 41 – Enhanced Combobox Class Hierarchy
Using SECComboBoxEx
The following procedures describe how to use an enhanced combo box in your application.
To add SECComboBoxEx to a window:
Use the CComboBox::Create() method. For example:
CRect(10,10,350,100), this, ID_COMBOBOX);
To add string items to the combo box:
Use the CComboBox::InsertItem() method. For example:
memset(&comboItem, 0, sizeof(comboItem));
comboItem.mask = CBEIF_TEXT;
comboItem.iItem = 0;
comboItem.pszText = _T("<stingray-installdir>\\Include");
where <stingray-installdir> refers to the top-level directory in your Stingray Studio installation.
To set the case sensitivity for the autocomplete feature:
Call the CComboBox::SetCaseSensitive() method.
The preceding call ensures that the autocomplete feature does not consider the case of the characters when it searches for a matching entry in the list.
To allow users to skip repeating delimiters:
Use the CComboBox::SetDelimiterKey() and SetDelimiterString() methods. For example, if the combobox contains long directory entries delimited by two backslashes, you can let the user skip the next delimiter by pressing the <TAB> key with the following calls.