CComboBox in a Modeless Dialog
-
OK, I'm going mad here. I have a dialog class which I am creating from a dialog resource and displaying as modeless. I have data members assigned to the various controls and most of them work fine, except the CComboBox data member. I am trying to add some string data to the control in the CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) but it asserts because the control's hwnd is null. Do I need to do anything special with a CComboBox? My code is like this...
int CFlushDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;SetWindowPos(NULL, m\_nXPos, m\_nYPos, 0, 0, SWP\_NOSIZE | SWP\_NOZORDER); m\_comboDataMember.AddString("Hello"); // BOOM! // Other data members CEdit, CButton work OK return 0;
}
I display the dialog like this...
m\_flushDialog.Create(IDD\_FLUSH\_DLG, this); m\_flushDialog.ShowWindow(SW\_SHOW);
Anyone have any ideas? :confused: Tony
-
OK, I'm going mad here. I have a dialog class which I am creating from a dialog resource and displaying as modeless. I have data members assigned to the various controls and most of them work fine, except the CComboBox data member. I am trying to add some string data to the control in the CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) but it asserts because the control's hwnd is null. Do I need to do anything special with a CComboBox? My code is like this...
int CFlushDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;SetWindowPos(NULL, m\_nXPos, m\_nYPos, 0, 0, SWP\_NOSIZE | SWP\_NOZORDER); m\_comboDataMember.AddString("Hello"); // BOOM! // Other data members CEdit, CButton work OK return 0;
}
I display the dialog like this...
m\_flushDialog.Create(IDD\_FLUSH\_DLG, this); m\_flushDialog.ShowWindow(SW\_SHOW);
Anyone have any ideas? :confused: Tony
Why don't you add the data to the combobox in the OnInitDialog method ?
Watched code never compiles.
-
OK, I'm going mad here. I have a dialog class which I am creating from a dialog resource and displaying as modeless. I have data members assigned to the various controls and most of them work fine, except the CComboBox data member. I am trying to add some string data to the control in the CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) but it asserts because the control's hwnd is null. Do I need to do anything special with a CComboBox? My code is like this...
int CFlushDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;SetWindowPos(NULL, m\_nXPos, m\_nYPos, 0, 0, SWP\_NOSIZE | SWP\_NOZORDER); m\_comboDataMember.AddString("Hello"); // BOOM! // Other data members CEdit, CButton work OK return 0;
}
I display the dialog like this...
m\_flushDialog.Create(IDD\_FLUSH\_DLG, this); m\_flushDialog.ShowWindow(SW\_SHOW);
Anyone have any ideas? :confused: Tony
-
I think you will find that your
ComboBox
does not get created until after the dialog creation has completed. Use theOnInitDialog()
function to handle intialisation of dialog controls.The best things in life are not things.
Thanks Richard (and also Maximilien), your suggestion works great. I wasnt aware that OnInitDialog() still got called with modeless dialogs. :-D :-D Tony
-
OK, I'm going mad here. I have a dialog class which I am creating from a dialog resource and displaying as modeless. I have data members assigned to the various controls and most of them work fine, except the CComboBox data member. I am trying to add some string data to the control in the CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) but it asserts because the control's hwnd is null. Do I need to do anything special with a CComboBox? My code is like this...
int CFlushDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;SetWindowPos(NULL, m\_nXPos, m\_nYPos, 0, 0, SWP\_NOSIZE | SWP\_NOZORDER); m\_comboDataMember.AddString("Hello"); // BOOM! // Other data members CEdit, CButton work OK return 0;
}
I display the dialog like this...
m\_flushDialog.Create(IDD\_FLUSH\_DLG, this); m\_flushDialog.ShowWindow(SW\_SHOW);
Anyone have any ideas? :confused: Tony
As others have suggested, all GUI initialization should occur in
OnInitDialog()
. The fact that some controls work is probably more of a coincidence in how they're implemented but should not be an indication that this is the proper place for this.