Office Style Flat ComboBox

.
For the latest updates and source code click here.

Office Style Flat ComboBox Demo

Environment: VC5, VC6, WIN9x, NT4

This control easily gives your application the Flat Look that is seen in the Microsoft office products. To use the control, simply add the files CCJFlatComboBox.cpp and CCJFlatComboBox.h to your project. You can use Class Wizard to add the CCJFlatComboBox member variables ( you most likely will have to rebuild the .clw file associated with your project ), or just replace any instance of CComboBox, with CCJFlatComboBox. Below is and example of how you might approach this.

Header file:

//{{AFX_DATA(CFlatComboDemoDlg)
enum { IDD = IDD_FLATCOMBODEMO_DIALOG };
CCJFlatComboBox m_DDCombo;
//}}AFX_DATA

Implementation file:

//{{AFX_DATA_MAP(CFlatComboDemoDlg)
DDX_Control(pDX, IDC_DROPDOWN_COMBO, m_DDCombo);
//}}AFX_DATA_MAP

Acknowledgements

  • Chris Maunder - For letting me use his color picker class. I made some modifications to the appearance of the control that is used in this demo. My modifications are noted.
  • Gilberto Botaro - For his help with adding auto completion to the CCJFlatComboBox class.
  • Vachik Hovhannissian and Danilo Lax - For help with fixing focus and message handling bugs.
  • Yosh Yamashita - For help with fixing accelerator bug.
  • Shannon McCoy - For suggestions on using ::GetSysColor(...) and ::GetSystemMetrics(...) more efficiently.
  • Todd Brannam - For help with fixing offset bug to use GetSystemMetrics().

Downloads

Download demo project - 46 Kb
Download source - 6 Kb


Comments

  • How to use the control in a DialogBar ???

    Posted by Legacy on 11/13/2002 12:00am

    Originally posted by: Weier

    It seems no DDX operation can be done in a dialogbar????

    Reply
  • *** WARNING *** This stuff is dangerous!

    Posted by Legacy on 12/12/2001 12:00am

    Originally posted by: Matthias Wolff

    I followd Kirks link to the "new" version of the combobox (www.codejock.com) and downloaded some of their demos.

    *****

    This software crashes Windows NT 4.0 (SP6) with a KMODE_EXCEPTION_NOT_HANDLED (or in simple words: a blue screen) as soon as you press any butten or open any menu.

    *****

    So if you love your NT you'd better keep off this stuff.

    Matthias

    Reply
  • BUG in CCJFlatComboBox::DrawCombo()

    Posted by Legacy on 12/06/2000 12:00am

    Originally posted by: TheFlashback

    Hi!
    
    

    neat code! looks very good. The only thing
    is that in the CCJFlatComboBox::DrawCombo() function
    you have the following:

    if (!IsWindowEnabled()) {
    return;
    }

    You should release the DC before returning as you
    do at the very end of this function.

    Thanks,

    TheFlashback

    Reply
  • Office style Combo : auto-incomplete

    Posted by Legacy on 11/29/1999 12:00am

    Originally posted by: Dennis McLeod

    The autocomplete feature works nicely as long as you don't want to back up beyond the matching part of your typed string. For instance... if you type "Some Mean" ... it autocompletes with the "Some Meaningless".. which is the desired result. However, If you now try to backspace because you wanted to type "Some Meanie".. it will not let you. You have to select and delete the whole string in order to start fresh.
    ~Dennis McLeod

    Reply
  • THE ARTICLE AND SOURCE CODE ARE OUTDATED, PLEASE FOLLOW THIS LINK FOR THE LATEST UPDATE

    Posted by Legacy on 09/12/1999 12:00am

    Originally posted by: Kirk Stowell

    Hello,

    Until I am able to update this article, as an alternative, please visit this link http://www.codejock.com/ for the latest updates. My email address has changed also, please respond to kstowell@codejock.com...

    Thanks,
    Kirk Stowell

    Reply
  • Scrollbar

    Posted by Legacy on 08/26/1999 12:00am

    Originally posted by: Paul Reynolds

    Where is the flat scrollbar drawing to go with the rest? Looks weird with it all being flat except the scrollbar...

    Reply
  • Tab functionality lost

    Posted by Legacy on 06/28/1999 12:00am

    Originally posted by: sheik

    when i press tab, it does not tab to other controls

    Reply
  • Where is the - 02 Nov 1998 - Added OnSetFocus(), OnKillFocus()... Code?

    Posted by Legacy on 02/03/1999 12:00am

    Originally posted by: Robert Clark

    The:

    02 Nov 1998 - Added OnSetFocus(), OnKillFocus() and modified OnPaint() so the control remains beveled until it actually looses focus - (Vachik Hovhannissian).

    code is not in the example listed here.

    I tried to implement it myself and it works fine for DROPDOWNLIST style combo boxes, but not for DROPDOWN style combo's which have a child EDIT control. The latter style does not receive the proper setfocus/killfocus messages, the child edit control gets them to the focus cannot be accurate.

    Has anybody experienced this and found a solution before?

    Reply
  • MS Thumbsize bug

    Posted by Legacy on 12/31/1998 12:00am

    Originally posted by: Shannon McCoy

    Running NT4 IE4SP1
    
    

    When testing your code to see if color changes where handled properly I noticed some painting glitches. If you go to the Control Panel->Display Appearence tab and change the scheme from "Windows Standard" to someting else like "Pumpkin(large)" the thumb doesn't paint right. Upon further testing I noticed that the thumbs in the combo box on the Display property sheet didn't resize either. The bug seems to be in MS's code. So instead of using GetSystemMeterics() on every paint you have to call it once during initialization and store the value. ( like in a member variable). Also instead of calling GetSystemColor() over and over it would be better to store the colors in member vars and handle the OnSystemColorChange message to reset them if neccesary IMHO.

    CFlatComboBox::CFlatComboBox()
    {
    m_bLBtnDown = false;
    m_Offset = ::GetSystemMetrics( SM_CXHTHUMB );
    m_ButtonHiliteColor = ::GetSysColor( COLOR_BTNHIGHLIGHT );
    m_ButtonShadowColor = ::GetSysColor( COLOR_BTNSHADOW );
    m_ButtonFaceColor = ::GetSysColor( COLOR_BTNFACE );
    }

    void CFlatComboBox::DrawCombo(DWORD dwStyle, COLORREF clrTopLeft, COLORREF clrBottomRight)
    {
    //Blah Blah Blah

    // Cover up dark 3D shadow on drop arrow.
    rcItem.DeflateRect(1,1);
    rcItem.left = rcItem.right- m_Offset;
    pDC->Draw3dRect(rcItem, m_ButtonFaceColor,
    m_ButtonFaceColor);

    //Blah Blah Blah
    }

    void CFlatComboBox::OnSysColorChange()
    {
    CComboBox::OnSysColorChange();

    m_ButtonHiliteColor = ::GetSysColor( COLOR_BTNHIGHLIGHT );
    m_ButtonShadowColor = ::GetSysColor( COLOR_BTNSHADOW );
    m_ButtonFaceColor = ::GetSysColor( COLOR_BTNFACE );

    }

    Reply
  • Inconsistencies compared to MSWord flat toolbar combos

    Posted by Legacy on 11/09/1998 12:00am

    Originally posted by: Lee Alexander

    The following is a list of inconsistencies the flat combo has compared with MSWord:
    
    

    1. The height of the control is not the same as MSWord even when the same font is used "Tahoma".

    2. When changing the default size of a scroll button via control panel the Flat Combo button when created has the same size (as is the case with normal Combos), however MSWord does not change based on this setting. I think it is better to follow the MSWord approach especially on toolbars.

    3. (Related to point 2) Drop button is not the same size as MSWord.


    4. When the control is disabled the drop arrow does bit have the same colour as MSWord flat combo.

    5. When the flat control gets focus it does not stay in 3D mode.

    Cheers Lee

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • 10 Rules that Make or Break Enterprise App Development Projects In today's app-driven world, application development is a top priority. Even so, 68% of enterprise application delivery projects fail. Designing and building applications that pay for themselves and adapt to future needs is incredibly difficult. Executing one successful project is lucky, but making it a repeatable process and strategic advantage? That's where the money is. With help from our most experienced project leads and software engineers, …

  • IT decision support impacts all aspects of technology management, from governance and strategy to budgets and resource planning. IT decision support effectiveness often falls prey to data-driven challenges that make it difficult to understand the data in context. These challenges: overwhelming data volumes, heterogeneous data types, and growing data complexity. This Forrester Consulting Paper reports the three key findings from their study conducted, on behalf of BDNA, to test the hypothesis that data …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds