CComBoxEx is a simple MFC control derived from
CWnd. It can display two line text in
A few days ago, in one of my projects, I need one
combobox control that could display two line text. Because the project time was tight, firstly I hoped that I could get some derived
combobox controls from The Code Project website, but I got nothing. Finally, I decided to make this control by myself. Now I completed this
combobox control, and it is not so bad for a VC++ beginner, so I decided to share this control with all CodeProject workmates. I did not have a lot of time to work on this control, so I had to code it in a simple manner, but it had to satisfy my requirements. It has some features as follows:
- It is simple, and easy to use.
- It is similar to the main functions of MFC
- It can display two line text.
combobox control is here. Enjoy and please help me with your invaluable notes, bugs reports, ideas, etc. that you think might improve the quality of this code.
Using the Code
Creating the Combobox Control
First, we need to create a two line text
- Add ComBoxEx.h and ComBoxEx.cpp to your project.
#include " ComBoxEx.h" to the top of header file of class in which you want to add this two line text control.
- Add a member variable of type
- In your cpp file, use the
Create method of the member variable to create a two line text
CStatic *pStatic = (CStatic *)GetDlgItem(IDC_COMBOBOX_STATIC);
m_ComboxEx.Create(rcStatic, this, 2000);
CString str1, str2;
str1 = "the first line data";
str2 = "the second line data";
str1 = "the third line data";
str2 = "the fourth line data";
str1 = "the fifth line data";
str2 = "the sixth line data";
Combobox control notify message
combobox control selects one item,
combobox control's parent window would receive
combobox control's notify message, you can do it like this.
afx_msg LRESULT OnComboboxNotify(WPARAM wParam, LPARAM lParam);
LRESULT CComboboxTextDlg::OnComboboxNotify(WPARAM wParam, LPARAM lParam)
TRACE("Combobox CtrlID = %d, CurSelNo = %d\n", wParam, lParam);
Next to Update
Combobox control is simple, and there are many functions that need update.
- Support font setting
combobox control uses the default font, and I didn't implement font setting functions.
Combobox auto size
Combobox control can't auto size, when you use it, you must set control height and width to fit content, next I will implement it.
Comboxlist support scroll bar
Combobox control calculates
comboxlist size according to
combobox control' size. When
combobox control items are very large,
comboxlist sizes are larger than screen size, it can't display all items on screen.
Combobox support item data
You know MFC
combobox control support information for every item, next to update this
combobox control and support this function.
- Support dropdown style
combobox control does not support this style, next add to it.
- 2011/11/22 Create