Two successive dialogs in a dlg app
-
Hello, I'd like to run two successive dialogs in my dialog application. The problem is that when the user exits the first one and the application tries to run the second, it fails (I suspect the message pump gets destroyed). I've tried creating a dummy window (so that there would always be at least one message target) before running the first dialog but that didn't help) Any helps? Can I re-ren the pump again or prevent it from ceasing? Thanks
-
Hello, I'd like to run two successive dialogs in my dialog application. The problem is that when the user exits the first one and the application tries to run the second, it fails (I suspect the message pump gets destroyed). I've tried creating a dummy window (so that there would always be at least one message target) before running the first dialog but that didn't help) Any helps? Can I re-ren the pump again or prevent it from ceasing? Thanks
-
dlg = new CPoolDlg; m_pMainWnd = dlg; int nResponse = dlg->DoModal(); delete dlg; playoff_dlg = new CPlayoffDlg; m_pMainWnd = playoff_dlg; nResponse = playoff_dlg->DoModal(); delete playoff_dlg; That's the code in InitInstance. I have to say I'm in no way a MFC guru. I played with the code a bit to make the CPoolDlg and CPlayoffDlg members of the CMyApp, and had to make them * in order to be able to create them after the common controls initialization is done. If I comment the first dialog out, the second runs wo problems, if I don't, the DoModal returns -1 (from what I know on some message pump checking call)
-
dlg = new CPoolDlg; m_pMainWnd = dlg; int nResponse = dlg->DoModal(); delete dlg; playoff_dlg = new CPlayoffDlg; m_pMainWnd = playoff_dlg; nResponse = playoff_dlg->DoModal(); delete playoff_dlg; That's the code in InitInstance. I have to say I'm in no way a MFC guru. I played with the code a bit to make the CPoolDlg and CPlayoffDlg members of the CMyApp, and had to make them * in order to be able to create them after the common controls initialization is done. If I comment the first dialog out, the second runs wo problems, if I don't, the DoModal returns -1 (from what I know on some message pump checking call)
search in the MSDN for Q138681 or just comment the m_pMainWnd lines out.
dlg = new CPoolDlg;
//m_pMainWnd = dlg;
int nResponse = dlg->DoModal();delete dlg;
playoff_dlg = new CPlayoffDlg;
//m_pMainWnd = playoff_dlg;nResponse = playoff_dlg->DoModal();
delete playoff_dlg; -
dlg = new CPoolDlg; m_pMainWnd = dlg; int nResponse = dlg->DoModal(); delete dlg; playoff_dlg = new CPlayoffDlg; m_pMainWnd = playoff_dlg; nResponse = playoff_dlg->DoModal(); delete playoff_dlg; That's the code in InitInstance. I have to say I'm in no way a MFC guru. I played with the code a bit to make the CPoolDlg and CPlayoffDlg members of the CMyApp, and had to make them * in order to be able to create them after the common controls initialization is done. If I comment the first dialog out, the second runs wo problems, if I don't, the DoModal returns -1 (from what I know on some message pump checking call)
The problem you have is that you are setting the m_pMainWin to be a pointer to your first dialog. MFC automatically terminates the thread (your application) when the window that m_pMainWnd is pointing to is closed. For further information see MSDN. You could change the code to:
dlg = new CPoolDlg;
playoff_dlg = new CPlayoffDlg;
m_pMainWnd = playoff_dlg;int nResponse = dlg->DoModal();
delete dlg;
nResponse = playoff_dlg->DoModal();
delete playoff_dlg;
Which will ensure that the application lives for the duration of the second dialog. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain) -
The problem you have is that you are setting the m_pMainWin to be a pointer to your first dialog. MFC automatically terminates the thread (your application) when the window that m_pMainWnd is pointing to is closed. For further information see MSDN. You could change the code to:
dlg = new CPoolDlg;
playoff_dlg = new CPlayoffDlg;
m_pMainWnd = playoff_dlg;int nResponse = dlg->DoModal();
delete dlg;
nResponse = playoff_dlg->DoModal();
delete playoff_dlg;
Which will ensure that the application lives for the duration of the second dialog. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)