Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Two successive dialogs in a dlg app

Two successive dialogs in a dlg app

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CaesarCZ
    wrote on last edited by
    #1

    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

    W 1 Reply Last reply
    0
    • C CaesarCZ

      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

      W Offline
      W Offline
      wb
      wrote on last edited by
      #2

      show the code.

      C 1 Reply Last reply
      0
      • W wb

        show the code.

        C Offline
        C Offline
        CaesarCZ
        wrote on last edited by
        #3

        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)

        W A 2 Replies Last reply
        0
        • C CaesarCZ

          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)

          W Offline
          W Offline
          wb
          wrote on last edited by
          #4

          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;

          1 Reply Last reply
          0
          • C CaesarCZ

            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)

            A Offline
            A Offline
            Antony M Kancidrowski
            wrote on last edited by
            #5

            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)

            C 1 Reply Last reply
            0
            • A Antony M Kancidrowski

              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)

              C Offline
              C Offline
              CaesarCZ
              wrote on last edited by
              #6

              Thank you both guys, it works now:)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups