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

ComboBox

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
6 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.
  • W Offline
    W Offline
    W Hammer sledge
    wrote on last edited by
    #1

    :confused:I am using the MFC. I have created a dialog, which has a static control and a comboBox, both elements have membervariables. I want to show the dialog like this: .... CMyDialogDlg mydialog; mydialog.m_static.SetWindowText("this works"); mydialog.m_combo.AddString("this crashes"); mydialog.DoModal(); .... There is no problem setting the windowtext of the staticcontrol. But if i use AddString before the dialog is shown by DoModal(), it crashes. If i use AddString in InitDialog() , it works. Can you explain me why?? what have i forgotten?

    R T 2 Replies Last reply
    0
    • W W Hammer sledge

      :confused:I am using the MFC. I have created a dialog, which has a static control and a comboBox, both elements have membervariables. I want to show the dialog like this: .... CMyDialogDlg mydialog; mydialog.m_static.SetWindowText("this works"); mydialog.m_combo.AddString("this crashes"); mydialog.DoModal(); .... There is no problem setting the windowtext of the staticcontrol. But if i use AddString before the dialog is shown by DoModal(), it crashes. If i use AddString in InitDialog() , it works. Can you explain me why?? what have i forgotten?

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      AddString() sends a message to a window that hasn't been created yet. You can't do this. You have to call it after the window has been created - OnInitDialog() is the place to do it. Hope this helps,

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      W 1 Reply Last reply
      0
      • R Ryan Binns

        AddString() sends a message to a window that hasn't been created yet. You can't do this. You have to call it after the window has been created - OnInitDialog() is the place to do it. Hope this helps,

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        W Offline
        W Offline
        W Hammer sledge
        wrote on last edited by
        #3

        Thanks, as i mentioned, I know that it works, if i put this in InitDialog (or OnInitDialog() ) . But why does it work with a static control or a textbox? sledge

        R 1 Reply Last reply
        0
        • W W Hammer sledge

          Thanks, as i mentioned, I know that it works, if i put this in InitDialog (or OnInitDialog() ) . But why does it work with a static control or a textbox? sledge

          R Offline
          R Offline
          Ryan Binns
          wrote on last edited by
          #4

          W. Hammer -sledge- wrote: But why does it work with a static control or a textbox? No idea. It shouldn't work. I wouldn't do it there anyway. Dialog boxes are responsible for showing the data. The class or function that uses the dialog box is responsibe for giving it the data - the dialog should then set the controls to reflect that data - the calling function shouldn't really need any knowledge of how the data is shown to the user.

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          C 1 Reply Last reply
          0
          • R Ryan Binns

            W. Hammer -sledge- wrote: But why does it work with a static control or a textbox? No idea. It shouldn't work. I wouldn't do it there anyway. Dialog boxes are responsible for showing the data. The class or function that uses the dialog box is responsibe for giving it the data - the dialog should then set the controls to reflect that data - the calling function shouldn't really need any knowledge of how the data is shown to the user.

            Ryan

            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

            C Offline
            C Offline
            conio
            wrote on last edited by
            #5

            this code would not budge because you are trying to add the strings to some objects which aren't even created, forget about the initialization which is manatory for the working of the gui object The Debugger:omg:

            1 Reply Last reply
            0
            • W W Hammer sledge

              :confused:I am using the MFC. I have created a dialog, which has a static control and a comboBox, both elements have membervariables. I want to show the dialog like this: .... CMyDialogDlg mydialog; mydialog.m_static.SetWindowText("this works"); mydialog.m_combo.AddString("this crashes"); mydialog.DoModal(); .... There is no problem setting the windowtext of the staticcontrol. But if i use AddString before the dialog is shown by DoModal(), it crashes. If i use AddString in InitDialog() , it works. Can you explain me why?? what have i forgotten?

              T Offline
              T Offline
              Terry ONolley
              wrote on last edited by
              #6

              I thought I read somewhere (yeah I know, real scientific.....) that static controls are available as soon as the dialog box they live in is instantiated. Combo boxes call malloc when they are created and contain pointers internally. Trying to call them before they are properly initialized will crash you.

              I'm going to live forever or die trying!

              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