How to create modal dlg in CWinapp?

Hi, I have a question.

In CWinApp, InitInstance() func has those things.
...

CMyDlg tdlg;
m_pMainWnd = &tdlg;
INT_PTR ret=tdlg.DoModal();
..

I wanted to show another dlg right after CMydlg destoryed, so I did like this.
CMyDlg tdlg;
m_pMainWnd = &tdlg;
INT_PTR ret=tdlg.DoModal();
if(ret == IDOK)
{}
else if(IDCANCEL)
{ return FALSE;}

CMyDlg2 tdlg2;
m_pMainWnd = &tdlg2;
tdlg2.doModal();
...

However, once CMyDlg returns IDOK, CMyDlg2.doModal()'s also termiated.

I need to know mfc process or something related to the reason i mentioned.

Anyone explain and help me.

Thanks. :)
Last edited on
Have you not already asked this question 3 weeks ago??
I guess i did. but i needed to arrange my question cuz what I asked was not that clear. So, I re-post it. Plz understand me. :)
It is all the way that MFC works:

The CWinApp class is derived from The CWinThread class.

The m_pMainWnd member is in the CWinThread baseclass.

When the main window dies, then the CWinThread also effectively dies.

so when you first do this:
1
2
3
CMyDlg tdlg;
m_pMainWnd = &tdlg; 
tdlg.DoModal();//show first dialogbox OK - afther dialogbox finishes, the thread dies with it. 


But once that first Dialogbox finishes, it also finishes the associated thread
so when you try to use it again

1
2
3
CMyDlg2 tdlg2;
m_pMainWnd = &tdlg2;
tdlg2.doModal(); //nothing happens because the thread that runs the dialogbox is dead  



Last edited on
If you have a dialog box you should be able to call doModal until the cows come home.
while (dB.doModal() == IDOK);
@ LowestOne - Not quite.

we are talking MFC and about changing the m_pMainWnd member of the CWinApp.




Thanks all.
And I got your saying, guestgulkan.
Thank you again.
Topic archived. No new replies allowed.