Click here to Skip to main content
11,920,394 members (50,007 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked

Two Line Text Combobox

, 14 Dec 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
CComBoxEx is a simple MFC control derived from CWnd, it can display two line data


CComBoxEx is a simple MFC control derived from CWnd. It can display two line text in combobox control.


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:

  1. It is simple, and easy to use.
  2. It is similar to the main functions of MFC combobox control.
  3. It can display two line text.

Now the 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 combobox control.

  1. Add ComBoxEx.h and ComBoxEx.cpp to your project.
  2. Add #include " ComBoxEx.h" to the top of header file of class in which you want to add this two line text control.
  3. Add a member variable of type CComBoEx.
  4. In your cpp file, use the Create method of the member variable to create a two line text combobox control.
    // create combobox control
    // to get combobox control position
    CStatic *pStatic = (CStatic *)GetDlgItem(IDC_COMBOBOX_STATIC);
    CRect rcStatic;
    // to create combobox control
    m_ComboxEx.Create(rcStatic, this, 2000);
    // add data to combobox control
    CString str1, str2;
    str1 = "the first line data";
    str2 = "the second line data";
    m_ComboxEx.AddString(str1, str2);
    str1 = "the third line data";
    str2 = "the fourth line data";
    m_ComboxEx.AddString(str1, str2);
    str1 = "the fifth line data";
    str2 = "the sixth line data";
    m_ComboxEx.AddString(str1, str2);
    // set combobox current selected item
    // Get Combobox Control Current Selected Item
  5. Combobox control notify message

    When combobox control selects one item, combobox control's parent window would receive combobox control's notify message, you can do it like this.

    // first declare msg response function in parent window header, under
    //}}AFX_MSG and up DECLARE_MESSAGE_MAP(), just like this.
    	afx_msg LRESULT OnComboboxNotify(WPARAM wParam, LPARAM lParam);
    	// second map combobox msg, between 
             // BEGIN_MESSAGE_MAP and END_MESSAGE_MAP(), just like this.
    BEGIN_MESSAGE_MAP(CComboboxTextDlg, CDialog)
    	// finally, code combobox msg process function
    	LRESULT CComboboxTextDlg::OnComboboxNotify(WPARAM wParam, LPARAM lParam)
    		TRACE("Combobox CtrlID = %d, CurSelNo = %d\n", wParam, lParam);
    		return 1;

Next to Update

This Combobox control is simple, and there are many functions that need update.

  1. Support font setting

    Now this combobox control uses the default font, and I didn't implement font setting functions.

  2. 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.

  3. 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.

  4. Combobox support item data

    You know MFC combobox control support information for every item, next to update this combobox control and support this function.

  5. Support dropdown style

    Now this combobox control does not support this style, next add to it.


  • 2011/11/22 Create combobox control


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

China China
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionPossible in dot net Pin
mayur csharp G14-Dec-11 22:54
membermayur csharp G14-Dec-11 22:54 
AnswerRe: Possible in dot net Pin
mengxz14-Mar-12 23:00
membermengxz14-Mar-12 23:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151120.1 | Last Updated 14 Dec 2011
Article Copyright 2011 by mengxz
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid