• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

mutiple dialog box

hi all, i just started using MFC to develop a small dialog based application on pocket PC. im using embedded visual c++ 4.0. my question is, after loading the initial screen(dialog box), how can i switch to another dialog box. i had the following code:

      CFirstDlg dlg1;
      m_pMainWnd = &dlg1;
      int nResponse = dlg1.DoModal();
      if (nResponse == IDOK)
      {
            CSecondDlg dlg2;
            m_pMainWnd = &dlg2;
            dlg2.DoModal();
      }

the fist dialog box closes successfully, but the second dialog box doesn't show up onto the screen and it seems like the program terminates after then. CFirstDlg is created by the wizard at the beginning as the initial screen. im thinking maybe there's something i have to declare in the defination of CSecondDlg class. but im not sure exactly what. some sample code is welcomed. thanks in advance.
0
yuexb
Asked:
yuexb
  • 2
  • 2
  • 2
  • +2
1 Solution
 
Jaime OlivaresCommented:
put a messagebox inside the if() to know if it is going in.
0
 
yuexbAuthor Commented:
im sure the code in the if statement is executed. i think there should be some code in in the CSecondDlg class definition that initializes the class.
0
 
Jaime OlivaresCommented:
try to use a common dialog like CFileDialog to discard
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Roshan DavisCommented:
try this one
     CFirstDlg dlg1;
     int nResponse = dlg1.DoModal();
     if (nResponse == IDOK)
     {
          CSecondDlg dlg2;
          m_pMainWnd = &dlg2;
          dlg2.DoModal();
     }
seems some message pumping issue... let me check...
~roshan
0
 
Roshan DavisCommented:
try this

Place a message map entry for the WM_NCDESTROY message in the CMyDialog class implementation file.

         ON_WM_NCDESTROY()



Add the OnNcDestory member function to the CMyDialog class and set the m_pMainWnd member variable of the application object to NULL.

         void CMyDialog::OnNcDestroy()
         {
            AfxGetApp()->m_pMainWnd = NULL;
            CDialog::OnNcDestroy();
         }


~roshan
0
 
yuexbAuthor Commented:
i tried the code, but its not giving me anything new. im thinking there's something missing in the constructor of CSecondDlg, which defines the dialog box that i want to bring up to the screen. here's my code for CSecondDialog:

CSecondDlg::CSecondDlg(CWnd* pParent /*=NULL*/)
      : CDialog(CSecondDlg::IDD, pParent)
{

}


void CSecondDlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSecondDlg, CDialog)
END_MESSAGE_MAP()

is there anything i should add?? thanks in advance.

xiao
0
 
Julian HansenCommented:
It appears that a WM_QUIT message is being posted after the first dialog closes.

In the DoModal function DlgCore.cpp there is a call to

VERIFY(RunModalLoop(dwFlags) == m_nModalResult) ;

This goes to function RunModalLoop in Wincore.cpp

There is an endless for loop in this function that has an embedded do while

This is where the code exits - it gets a WM_QUIT and returns

                  if (!AfxPumpMessage())
                  {
                        AfxPostQuitMessage(0);
                        return -1;
                  }

Not sure why ...
0
 
NawalKishore1976Commented:
Use the following code
means comment or delete:
//      m_pMainWnd = &dlg;


CTempDlg dlg;
//      m_pMainWnd = &dlg;
      int nResponse = dlg.DoModal();
      if (nResponse == IDOK)
      {
            CD d;
            d.DoModal();

      }
      else if (nResponse == IDCANCEL)
      {
            // TODO: Place code here to handle when the dialog is
            //  dismissed with Cancel
      }
0
 
NawalKishore1976Commented:
In Dialog Box Application if you set
m_pMainWnd = &dlg;
then the main window is the dialog box.
In MFC if you close the main window, the progam is supposed to quit.
That is what is happening
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now