ComboBox
-
: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? -
: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?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"
-
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"
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
-
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
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"
-
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"
-
: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?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!