Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating a combobox & checkbox dynamically

Creating a combobox & checkbox dynamically

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PrashantJ
    wrote on last edited by
    #1

    Hi, I have pasted a peice of code that I use to create the combo box dynamically, but found that it draws a edit box, not a combo box. CComboBox m_schemaCombo; m_schemaCombo.CreateEx( WS_EX_CLIENTEDGE, _T("COMBOBOX"), NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_NUMBER, CRect(row3, frameTop + 3 * topBottomOffset + buttonHeight3, editBoxWidth, frameTop + 3 * topBottomOffset + buttonHeight2 + buttonHeight2), this, IDC_SCHEMA_COMBO, 0 ); m_schemaCombo.SetFont( GetFont() ); Very sceptical about the 2nd argument of CreateEx. Can anybody help me out? Also, please let me know the way to create a checkbox also. Thanks, Prashant

    D A D 4 Replies Last reply
    0
    • P PrashantJ

      Hi, I have pasted a peice of code that I use to create the combo box dynamically, but found that it draws a edit box, not a combo box. CComboBox m_schemaCombo; m_schemaCombo.CreateEx( WS_EX_CLIENTEDGE, _T("COMBOBOX"), NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_NUMBER, CRect(row3, frameTop + 3 * topBottomOffset + buttonHeight3, editBoxWidth, frameTop + 3 * topBottomOffset + buttonHeight2 + buttonHeight2), this, IDC_SCHEMA_COMBO, 0 ); m_schemaCombo.SetFont( GetFont() ); Very sceptical about the 2nd argument of CreateEx. Can anybody help me out? Also, please let me know the way to create a checkbox also. Thanks, Prashant

      D Offline
      D Offline
      dipeka
      wrote on last edited by
      #2

      Try using the CComboboxEx class instead of the Combobox class. I'm not very sure but I hope this is useful Dipeka.A.J

      P 1 Reply Last reply
      0
      • D dipeka

        Try using the CComboboxEx class instead of the Combobox class. I'm not very sure but I hope this is useful Dipeka.A.J

        P Offline
        P Offline
        PrashantJ
        wrote on last edited by
        #3

        No CComboBoxEx did'nt help.... -Prashant

        1 Reply Last reply
        0
        • P PrashantJ

          Hi, I have pasted a peice of code that I use to create the combo box dynamically, but found that it draws a edit box, not a combo box. CComboBox m_schemaCombo; m_schemaCombo.CreateEx( WS_EX_CLIENTEDGE, _T("COMBOBOX"), NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_NUMBER, CRect(row3, frameTop + 3 * topBottomOffset + buttonHeight3, editBoxWidth, frameTop + 3 * topBottomOffset + buttonHeight2 + buttonHeight2), this, IDC_SCHEMA_COMBO, 0 ); m_schemaCombo.SetFont( GetFont() ); Very sceptical about the 2nd argument of CreateEx. Can anybody help me out? Also, please let me know the way to create a checkbox also. Thanks, Prashant

          D Offline
          D Offline
          dipeka
          wrote on last edited by
          #4

          I think the third parameter of createex cannot be NULL. Try using this->m_hWnd(pointer to parent dialog). Hope this helps Dipeka.A.J

          1 Reply Last reply
          0
          • P PrashantJ

            Hi, I have pasted a peice of code that I use to create the combo box dynamically, but found that it draws a edit box, not a combo box. CComboBox m_schemaCombo; m_schemaCombo.CreateEx( WS_EX_CLIENTEDGE, _T("COMBOBOX"), NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_NUMBER, CRect(row3, frameTop + 3 * topBottomOffset + buttonHeight3, editBoxWidth, frameTop + 3 * topBottomOffset + buttonHeight2 + buttonHeight2), this, IDC_SCHEMA_COMBO, 0 ); m_schemaCombo.SetFont( GetFont() ); Very sceptical about the 2nd argument of CreateEx. Can anybody help me out? Also, please let me know the way to create a checkbox also. Thanks, Prashant

            A Offline
            A Offline
            Antti Keskinen
            wrote on last edited by
            #5

            The answer is quite simple. What you are doing here is calling CWnd::CreateEx, that allows you to create child windows. However, there is a function call CComboBox::Create that will create a combo box control and attach it to the CComboBox object. The calling convention for Create is a bit different, as you only need to supply the standard flags, rectangle, pointer to parent CWnd and the ID. This call doesn't allow you to specify extended window flags. But you can use GetExStyle, a bit mask and SetWindowLong to set the client edge extended style. Another reason why it creates an edit box might be because of the ES_NUMBER flag. This flag is meant for edit controls, not comboboxes. All combobox flags start with CBS_ prefix. Try removing it and see what happens. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

            1 Reply Last reply
            0
            • P PrashantJ

              Hi, I have pasted a peice of code that I use to create the combo box dynamically, but found that it draws a edit box, not a combo box. CComboBox m_schemaCombo; m_schemaCombo.CreateEx( WS_EX_CLIENTEDGE, _T("COMBOBOX"), NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_NUMBER, CRect(row3, frameTop + 3 * topBottomOffset + buttonHeight3, editBoxWidth, frameTop + 3 * topBottomOffset + buttonHeight2 + buttonHeight2), this, IDC_SCHEMA_COMBO, 0 ); m_schemaCombo.SetFont( GetFont() ); Very sceptical about the 2nd argument of CreateEx. Can anybody help me out? Also, please let me know the way to create a checkbox also. Thanks, Prashant

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              How about:

              CComboBox m_schemaCombo;
              m_schemaCombo.Create(WS_CHILDWINDOW | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWN,
              CRect(row3,
              frameTop + 3 * topBottomOffset + buttonHeight3,
              editBoxWidth,
              frameTop + 3 * topBottomOffset + buttonHeight2 + buttonHeight2),
              this, IDC_SCHEMA_COMBO);
              m_schemaCombo.SetFont(GetFont());


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              P 1 Reply Last reply
              0
              • D David Crow

                How about:

                CComboBox m_schemaCombo;
                m_schemaCombo.Create(WS_CHILDWINDOW | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWN,
                CRect(row3,
                frameTop + 3 * topBottomOffset + buttonHeight3,
                editBoxWidth,
                frameTop + 3 * topBottomOffset + buttonHeight2 + buttonHeight2),
                this, IDC_SCHEMA_COMBO);
                m_schemaCombo.SetFont(GetFont());


                "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                P Offline
                P Offline
                PrashantJ
                wrote on last edited by
                #7

                Thanks David....It worked.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups