CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Dec 2009
    Posts
    161

    Combo Box Styles

    Hi,

    I am creating a combo box via C++ code in order to abtain the third combobox on the right shown in the picture below:



    The following is the code:

    Code:
    HWND hvComboBox = CreateWindowEx(0,WC_COMBOBOX,NULL,
    WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | 0x00002000,
    60, 62, 250, 100,
    hwnd,(HMENU)IDC_COMBO1,hInst,NULL);
    where I guess the 0x00002000 should give the combobox that special style (the control was originally created with ResEdit)

    Unfortunately, I am still getting a normal style like the combo in the middle shown in the picture...what am I doing wrong?

    thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Combo Box Styles

    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Dec 2009
    Posts
    161

    Re: Combo Box Styles

    I checked them out, still I can't find the style ResEdit created

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Combo Box Styles

    Code:
    /*
     * Combo Box styles
     */
    #define CBS_SIMPLE            0x0001L
    #define CBS_DROPDOWN          0x0002L
    #define CBS_DROPDOWNLIST      0x0003L
    #define CBS_OWNERDRAWFIXED    0x0010L
    #define CBS_OWNERDRAWVARIABLE 0x0020L
    #define CBS_AUTOHSCROLL       0x0040L
    #define CBS_OEMCONVERT        0x0080L
    #define CBS_SORT              0x0100L
    #define CBS_HASSTRINGS        0x0200L
    #define CBS_NOINTEGRALHEIGHT  0x0400L
    #define CBS_DISABLENOSCROLL   0x0800L
    #if(WINVER >= 0x0400)
    #define CBS_UPPERCASE         0x2000L
    #define CBS_LOWERCASE         0x4000L
    #endif /* WINVER >= 0x0400 */
    
    #endif  /* !NOWINSTYLES */

  5. #5
    Join Date
    Dec 2009
    Posts
    161

    Re: Combo Box Styles

    ok, thanks. Yet, it seems there's no way to make it look like that

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Combo Box Styles

    CBS_DROPDOWNLIST should do that. Maybe I didn't understand your question. What is the problem?

  7. #7
    Join Date
    Dec 2009
    Posts
    161

    Re: Combo Box Styles

    I get a regular combobox, I dont get the third on the left shown in teh picture I posted

  8. #8
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Combo Box Styles

    Here's an (almost) cut-n-past of your code:

    Code:
      HWND hvComboBox1,hvComboBox2,hvComboBox3;
      HINSTANCE hInst=AfxGetInstanceHandle();
    
      hvComboBox1 = CreateWindowEx(0,WC_COMBOBOX,L"CBS_DROPDOWNLIST",
    WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | 0x00002000,
    60, 62, 250, 100,
    m_hWnd,NULL,hInst,NULL);
    
      hvComboBox2 = CreateWindowEx(0,WC_COMBOBOX,L"CBS_DROPDOWN",
    WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_HASSTRINGS | WS_VSCROLL | 0x00002000,
    60, 92, 250, 100,
    m_hWnd,NULL,hInst,NULL);
    
      hvComboBox3 = CreateWindowEx(0,WC_COMBOBOX,L"CBS_SIMPLE",
    WS_CHILD | WS_VISIBLE | CBS_SIMPLE | CBS_HASSTRINGS | WS_VSCROLL | 0x00002000,
    60, 122, 250, 100,
    m_hWnd,NULL,hInst,NULL);
    Gives me this:


  9. #9
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Combo Box Styles

    Quote Originally Posted by THEARTOFWEB View Post
    I get a regular combobox, I dont get the third on the left shown in teh picture I posted
    Are you talking about its look or its behavior?
    The “regular” combobox allows you to edit your entry, while the CBS_DROPDOWNLIST – only to pick from the list.
    If you are concerned about the look – this is most likely controlled by your theme and depends on the version of Windows.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  10. #10
    Join Date
    Dec 2009
    Posts
    161

    Re: Combo Box Styles

    Quote Originally Posted by hoxsiew View Post
    Here's an (almost) cut-n-past of your code:

    Gives me this:

    that is not working for me :-( I am on windows vista...by the way, do you think I should use SetWindowTheme() to force a stlye?

    I guess I should turn to different gui libraries like QT or GTK+

  11. #11
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Combo Box Styles

    Only if you want to P*ss off your users. They chose the style; the program shouldn't second-guess them.

    My capture was from Windows 7 BTW, so it got me thinking that maybe you're not using the right manifest for common controls or something and are stuck with the old windows95 look.

    What exactly do you mean by "not working for me"? I assumed you meant that you were getting the wrong behavior from the control, but do you really mean the style doesn't look right?

  12. #12
    Join Date
    Dec 2009
    Posts
    161

    Re: Combo Box Styles

    Quote Originally Posted by hoxsiew View Post
    My capture was from Windows 7 BTW, so it got me thinking that maybe you're not using the right manifest for common controls or something and are stuck with the old windows95 look.

    What exactly do you mean by "not working for me"? I assumed you meant that you were getting the wrong behavior from the control, but do you really mean the style doesn't look right?
    Yeah, I am stuck with teh old win95 look. I tried your code and the style looks bad. Here's is an example (shown from ResEdit)



    while this is the same create via C++ code using CreateWindowEx for the main window and its single child controls:



    How come thru ResEdit I get that style whereas in pure code I don't?

    thanks

  13. #13
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Combo Box Styles

    Add a manifest dependency for Common controls 6.0 to your stdafx.h file:

    Code:
    #ifdef _UNICODE
    #if defined _M_IX86
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_IA64
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_X64
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #else
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #endif
    #endif

  14. #14
    Join Date
    Dec 2009
    Posts
    161

    Re: Combo Box Styles

    wow that's great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured