viksoe.dk

Various ComboBox controls


This article was submitted .


The following are all subclassed ComboBox controls and extended with extra functionality.

All controls are initialized the same way: either by creating a free-standing combobox, or by subclassing an existing control in a dialog.
Simply add a member variable to your dialog implementation file...

CColorPickerComboCtrl m_ctlPicker
In the OnInitDialog() event handler, add the following lines:
LRESULT OnInitDialog(UINT /*uMsg*/, 
                     WPARAM /*wParam*/, 
                     LPARAM /*lParam*/, 
                     BOOL& /*bHandled*/)
{
  ...
  m_ctlPicker.SubclassWindow(GetDlgItem(IDC_COMBO1));
  ...
}
Then add the following reflection macro to your dialog's message map:
  BEGIN_MSG_MAP(CMainDlg)
    ...
    REFLECT_NOTIFICATIONS()
  END_MSG_MAP()
Each control adds one or more additional methods for initializing, setting colours or what-ever. Most control were developed for non-themed Windows, so I'm not sure how they look under Windows XP.

ColorPicker Combo


The ColorPickerCombo control is a subclassed COMBOBOX Windows control, which contains coloured items to pick from. The control has the following colour-related methods:
AddColor(position, color)
RemoveColor(color)
SelectColor(color)
color = GetSelectedColor()
index = FindColor(color)

CheckCombo


The CheckCombo control is a subclassed COMBOBOX Windows control, which contains checkboxes in the list, The label part displays the current selection as a comma-separated text string. The control only works in Drop List mode. Multiple checkboxes can be checked at the same time. The control adds the following related methods:
AddString(str, checked)
SetCheckState(index, checked)
GetCheckState(index)
SetExtendedComboStyle()

FontCombo


The FontCombo control is a subclassed COMBOBOX Windows control, which display the list of currently installed fonts on the system. It can display fonts with their native face in the list, with TrueType and OpenType symbols and fonts with a fixed pitch in bold. The control introduces the following methods:
Dir(type, family)
GetLogFont(index)
GetTextMetrics(index)
SetExtendedFontStyle()

MRU Combo


The MruCombo control is a subclassed COMBOBOX Windows control, which exposes a Most Recently Used history in the dropdown. The list is persisted to the System Registry. The control has the following persist-related methods:
UpdateList()
AddToList(name)
ReadFromRegistry()
WriteToRegistry()
SetMaxEntries()
You must manually call ReadFromRegistry and WriteToRegistry to persist the history list. Also AddToList must be called to add new members (for instance in response to the user closing the dialog).

ReadOnlyCombo


The ReadOnlyCombo control is a subclassed COMBOBOX Windows control, which has the capability to display itself as read-only. The control adds the following method:
SetReadOnly(bool)

Tree Combo


The TreeCombo control is a hybrid between a COMBOBOX and a TREEVIEW tree control. It replaces the popup list with a tree control. The tree can be dynamically expanded to reveal nested groups and items. The control also introduces the following item-related methods:
InsertItem(...)
DeleteItem(treeitem)
ExpandItem(treeitem)
GetSelectedItem()
SelectItem(treeitem)
A lot of the original item-related methods are defunct in this control.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 7.5 Library

Download Files

DownloadSource Code (17 Kb)

To the top