Click here to Skip to main content
11,928,078 members (49,280 online)
Click here to Skip to main content
Add your own
alternative version


111 bookmarked

CheckComboBox Control

, 24 Nov 1999
Rate this:
Please Sign up or sign in to vote.
A combo box with check boxes.

Sample Image


What does a CheckComboBox control do? A combo box has always been a way of selecting one item from a list of several. If you need to select one or more items, you have to either use a multiple selection listbox or use the MFC's CCheckListBox. The only problem is that it takes up space in your dialog or form. What you need is a CCheckComboBox!

When I started to develop the control, I was planning to design a composite control consisting of a static control along with a small button. When clicking the button, a popup window would be displayed where the user could select or unselect the items. The problem was that it took too much code to implement. I wanted the look and feel just like a standard combo box and that was not possible with a reasonable amount of code.

So I decided to subclass the combo box. A problem when subclassing the combo box is that you have no window handle to the list portion of the combo box that you may subclass. You only have the combo box window handle and that doesn't help.

The trick is to listen to the WM_CTLCOLORLISTBOX message. When the WM_CTLCOLORLISTBOX message is sent, lParam contains the window handle of the list box. This is the time to do the subclassing.

The code below shows how this is done:

BEGIN_MESSAGE_MAP(CCheckComboBox, CComboBox)

LRESULT CCheckComboBox::OnCtlColorListBox(WPARAM wParam, LPARAM lParam) 
    // If the listbox hasn't been subclassed yet, do so...
    if (m_hListBox == 0) {
        HWND hWnd = (HWND)lParam;

        if (hWnd != 0 && hWnd != m_hWnd) {
           // Save the listbox handle
           m_hListBox = hWnd;

           // Do the subclassing
           m_pWndProc = (WNDPROC)GetWindowLong(m_hListBox, GWL_WNDPROC);
           SetWindowLong(m_hListBox, GWL_WNDPROC, (LONG)ComboBoxListBoxProc);

    return DefWindowProc(WM_CTLCOLORLISTBOX, wParam, lParam);

After this is done, the rest is fairly straight forward. The ComboBoxListBoxProc() routine takes care of selecting/unselecting items and key down events. The overridden DrawItem() routine draws both the list items and the static portion of the combo box. If it is an item, it draws a checkmark followed by the text. If it is the static portion, it draws the text from all selected items separated by the standard list separator.

Please note that the CCheckComboBox must be created with the CBS_DROPDOWNLIST and the CBS_OWNERDRAWVARIABLE styles set. Also the CBS_HASSTRINGS style must be specified since I let the combo box handle the item strings (sorting etc.).

Since the check mark information is stored in the combo box item data, this may not be used by the application. Setting it to zero unselects the item otherwise it selects the item. But use the GetCheck() and SetCheck() routines instead since they handle redrawing correctly. If you need your own item data, you must implement this yourself.

It is easy to use this control since it is derived from the MFC CComboBox. Add CheckComboBox.h and CheckComboBox.cpp to your project and use it as a standard CComboBox. When used inside a dialog, simply select the category "Control" and variable type "CCheckComboBox" under the "Member Variables" page of the Class Wizard. This will declare a member variable in your dialog of type CCheckComboBox ready for you to use.

Well, I hope someone finds this useful. At least I did.


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


About the Author

No Biography provided

You may also be interested in...

Comments and Discussions

BugUnicode problem Pin
C++ Hacker4-Nov-13 23:50
memberC++ Hacker4-Nov-13 23:50 
GeneralRe: Unicode problem Pin
Anurag Daware31-May-15 22:01
memberAnurag Daware31-May-15 22:01 
QuestionCCheckComboBox II & Pin
Eran SMS11-Jul-13 2:33
memberEran SMS11-Jul-13 2:33 
QuestionUnable to increase drop down wdith Pin
NipunG25-Sep-12 21:44
memberNipunG25-Sep-12 21:44 
AnswerRe: Unable to increase drop down wdith Pin
Member 1100787231-May-15 21:39
memberMember 1100787231-May-15 21:39 
bosfan31-Jul-12 2:31
memberbosfan31-Jul-12 2:31 
BugWin x64 fail Pin
AJG8514-May-12 14:13
memberAJG8514-May-12 14:13 
GeneralRe: Win x64 fail Pin
AJG8515-May-12 12:40
memberAJG8515-May-12 12:40 
QuestionHow to use GetDlgItem() Pin
amitwadekar17-Jan-12 3:08
memberamitwadekar17-Jan-12 3:08 
GeneralMy vote of 5 Pin
Emmo2-Jun-11 6:20
memberEmmo2-Jun-11 6:20 
GeneralMy vote of 5 Pin
Phil Outram6-Aug-10 6:00
memberPhil Outram6-Aug-10 6:00 
GeneralMy vote of 1 Pin
xinkmt3-Aug-10 16:09
memberxinkmt3-Aug-10 16:09 
GeneralBug - before subclassing behavior Pin
John59027-Aug-09 1:37
memberJohn59027-Aug-09 1:37 
GeneralRe: Bug - before subclassing behavior...and fix to get arrow keys opening drop down box Pin
Phil Outram6-Aug-10 6:23
memberPhil Outram6-Aug-10 6:23 
GeneralExcellent control Pin
simbakid26-Mar-09 23:14
membersimbakid26-Mar-09 23:14 
Questioncombobox show only one item at dropdown Pin
rotalume17-Jan-09 7:16
memberrotalume17-Jan-09 7:16 
AnswerRe: combobox show only one item at dropdown Pin
rotalume18-Jan-09 19:55
memberrotalume18-Jan-09 19:55 
QuestionCan you give more explain? Pin
paradise of pig20-Oct-08 9:35
memberparadise of pig20-Oct-08 9:35 
GeneralCan't see the List after click on the combo box. Pin
nankyu119-Oct-08 21:25
membernankyu119-Oct-08 21:25 
GeneralRe: Can't see the List after click on the combo box. Pin
Magnus Egelberg19-Oct-08 21:35
memberMagnus Egelberg19-Oct-08 21:35 
GeneralRe: Can't see the List after click on the combo box. Pin
nankyu119-Oct-08 22:05
membernankyu119-Oct-08 22:05 
GeneralRe: Can't see the List after click on the combo box. Pin
Martin Chapman20-Jan-10 18:20
memberMartin Chapman20-Jan-10 18:20 
GeneralRe: Can't see the List after click on the combo box. Pin
Martin Chapman20-Jan-10 18:27
memberMartin Chapman20-Jan-10 18:27 
GeneralRe: Can't see the List after click on the combo box. Pin
alex agger20-Jun-13 23:13
memberalex agger20-Jun-13 23:13 
GeneralRe: Can't see the List after click on the combo box. Pin
Member 1100787229-May-15 2:51
memberMember 1100787229-May-15 2:51 
Generalwhere can i find a version written by c# Pin
linzhuo25-Jun-08 23:10
memberlinzhuo25-Jun-08 23:10 
GeneralLicense Pin
lanreola26-Mar-08 7:12
memberlanreola26-Mar-08 7:12 
QuestionRe: License Pin
Scott Bartine6-Dec-11 11:11
memberScott Bartine6-Dec-11 11:11 
Questionhow to disable check box selection ? Pin
mrgoos19-Aug-07 5:40
membermrgoos19-Aug-07 5:40 
QuestionTool tip for Combo contol Pin
sajithomas21-Jun-07 23:52
membersajithomas21-Jun-07 23:52 
GeneralUsing CheckComboBox Pin
jives30-Apr-07 3:52
memberjives30-Apr-07 3:52 
tworca13-Apr-07 9:38
membertworca13-Apr-07 9:38 
Magnus Egelberg15-Apr-07 21:29
memberMagnus Egelberg15-Apr-07 21:29 
GeneralRe: Why not CB_GETCOMBOBOXINFO? Pin
Notre5-Nov-07 10:46
memberNotre5-Nov-07 10:46 
Generalcombocheckbox Pin
dnldldrch6-Dec-06 14:21
memberdnldldrch6-Dec-06 14:21 
GeneralRe: combocheckbox Pin
Magnus Egelberg6-Dec-06 23:53
memberMagnus Egelberg6-Dec-06 23:53 
QuestionOn resizing the dropdown list does not show up Pin
hoc_ngo15-May-06 14:15
memberhoc_ngo15-May-06 14:15 
GeneralBug Pin
Marek Konopka14-Mar-06 4:37
memberMarek Konopka14-Mar-06 4:37 
GeneralRe: Bug Pin
Marek Konopka14-Mar-06 4:51
memberMarek Konopka14-Mar-06 4:51 
Questionhow to change it to the dropdown style Pin
minibao6-Feb-06 3:52
memberminibao6-Feb-06 3:52 
AnswerRe: how to change it to the dropdown style Pin
.dan.g.9-Mar-06 15:51
member.dan.g.9-Mar-06 15:51 
GeneralRe: how to change it to the dropdown style Pin
Member 411759710-Nov-08 4:06
memberMember 411759710-Nov-08 4:06 
GeneralMutiple selection in the drop-down list box Pin
lanreola31-Aug-05 12:05
memberlanreola31-Aug-05 12:05 
GeneralRe: Mutiple selection in the drop-down list box Pin
.dan.g.9-Mar-06 15:58
member.dan.g.9-Mar-06 15:58 
GeneralFlat Checkbox Pin
Rafal Glowinski19-Jul-04 9:03
memberRafal Glowinski19-Jul-04 9:03 
GeneralThis is just what I need Pin
edger5-Feb-04 20:29
memberedger5-Feb-04 20:29 
Generalondropdown event Pin
GAOFENG00712-Nov-03 17:05
memberGAOFENG00712-Nov-03 17:05 
QuestionWinCE? Pin
ajh5-Sep-03 19:32
memberajh5-Sep-03 19:32 
AnswerRe: WinCE? Pin
João Paulo Figueira2-Oct-03 1:13
memberJoão Paulo Figueira2-Oct-03 1:13 
GeneralRe: WinCE? Pin
ajh2-Oct-03 6:11
memberajh2-Oct-03 6:11 

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
Web02 | 2.8.151126.1 | Last Updated 25 Nov 1999
Article Copyright 1999 by Magnus Egelberg, Lundalogik
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid