
Introduction
This is a simple sub classed control from CComboBox
that allows you to apply skin to the combobox
and its droplist
. The skins used can be a pixel wide (for the background and corners of the droplist
) to keep the control light.
The CComboBox Overrides
The following functions are overridden (just like in most of the sub classed controls). It's all easy to understand.
virtual BOOL Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CCreateContext* pContext = NULL);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg void OnPaint();
afx_msg void OnDestroy();
afx_msg LRESULT OnCtlColorListBox(WPARAM wParam, LPARAM lParam);
The following function is taken from the multicombobox
project on Code Project (sorry I forgot the author and link).
afx_msg LRESULT OnCtlColorListBox(WPARAM wParam, LPARAM lParam);
How to Use
It's very simple to use. Add a combobox
on the dialog box, make a member variable of CComboBox
type, change the type of object to CBitComboBox
in the Dialog header file, and add the bitmaps in the resource to skin the combobox
.
Change the header file to look as follows:
Include BitComboBox
header:
#include "BitComboBox.h"
Change the control's class to CBitComboBox
from CComboBox
.
CBitComboBox m_cmbBitmap;
Call the following functions in CBitComboBox
class to set resource IDs of the skin bitmaps on OnInitDialog
(or anywhere in your project before combobox
is created).
m_cmbBitmap.SetComboBitmap(IDB_COMBO_LEFT,
IDB_COMBO_RIGHT,IDB_COMBO_CEN);
m_cmbBitmap.SetComboListBitmap(IDB_LIST_LEFT,
IDB_LIST_RIGHT,IDB_LIST_TOP,IDB_LIST_BOT);
m_cmbBitmap.SetHighlightColor(RGB(115,138,174), RGB(255,255,255));
m_cmbBitmap.SetNormalPositionColor(RGB(115,138,154), RGB(255,255,255));
What is Missing
The following things are missing. If someone can complete them, please let me know:
- If there is no skin, set a default
combobox
should appear (can be done by simply calling the CComboBox
functions from overrides). - I have not implemented the skins for edit control of
combobox
(can be done in OnCtrlColor
of CBitComboBox
).
History
- 25th March, 2004: Initial version
License
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below. A list of licenses authors might use can be found here.