truble with making custom dlg

I customize a dialog like blow.

class ScDlg : public CDialog
{....
DECLARE_MESSAGE_MAP()
public:
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
}

And I made two classes based on ScDlg.
FirstDlg : ScDlg
SecondDlg : ScDlg

then I declare both two classes in App class like this.
FirstDlg dlg1;
m_pMainWnd = &dlg1;
INT_PTR nResponse1 = dlg1.DoModal();
if (nResponse1 == IDOK){ }
else if (nResponse1 == IDCANCEL){return false;}

SecondDlg dlg2;
m_pMainWnd = &dlg2;
INT_PTR nResponse2 = dlg2.DoModal();
if (nResponse2 == IDOK){ }
else if (nResponse2 == IDCANCEL){return false;}

First dlg perfectly works. When I pressed OK button,
it returns IDOK.
However, dlg2.DoModal() immediately returns -1.

I don't know why.

Please help me. I need your help. Thanks.

After some research - I have come to the conclusion that you cannot
change the m_pMainWnd the way you are doing it.

This might be a better way for your problem;

1
2
3
4
5
6
7
8
9
10
11
12
13
m_pMainWnd = NULL; //Do this instead - justthis to NULL and leave it

FirstDlg dlg1;
//m_pMainWnd = &dlg1; //Forget this
INT_PTR nResponse1 = dlg1.DoModal();
if (nResponse1 == IDOK){ }
else if (nResponse1 == IDCANCEL){return false;}

SecondDlg dlg2;
//m_pMainWnd = &dlg2;//Forget this
INT_PTR nResponse2 = dlg2.DoModal();
if (nResponse2 == IDOK){ }
else if (nResponse2 == IDCANCEL){return false;}


In reality it seems you don't need to set the CWinApp m_pMainWnd
at all - so you should be able to leave it alone in this case.
Last edited on
Thanks guestgulkan. It works.!!!
Topic archived. No new replies allowed.