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. how to simultaneously show 2 dialogs

how to simultaneously show 2 dialogs

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
10 Posts 6 Posters 0 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.
  • K Offline
    K Offline
    Krauze
    wrote on last edited by
    #1

    I'm now coding with VC++2008. I wanna show 2 dialogs at the same time. So how to achieve it? Thanks in advance. In fact I've tried the following:

    BOOL CDlg1::OnInitDialog()
    {
    ...
    dlg2.Create(IDD_DIALOG2, this); // where dlg2 is defined as a private CDlg2 varibale of CDlg1 in its header file
    dlg2.ShowWindow(SW_SHOW);
    ...
    }

    But this doesn't work.

    T L X F 4 Replies Last reply
    0
    • K Krauze

      I'm now coding with VC++2008. I wanna show 2 dialogs at the same time. So how to achieve it? Thanks in advance. In fact I've tried the following:

      BOOL CDlg1::OnInitDialog()
      {
      ...
      dlg2.Create(IDD_DIALOG2, this); // where dlg2 is defined as a private CDlg2 varibale of CDlg1 in its header file
      dlg2.ShowWindow(SW_SHOW);
      ...
      }

      But this doesn't work.

      T Offline
      T Offline
      transoft
      wrote on last edited by
      #2

      You can run two Modeless Dialog Boxes. following might help you. http://msdn.microsoft.com/en-us/library/ms644996%28VS.85%29.aspx[^]

      1 Reply Last reply
      0
      • K Krauze

        I'm now coding with VC++2008. I wanna show 2 dialogs at the same time. So how to achieve it? Thanks in advance. In fact I've tried the following:

        BOOL CDlg1::OnInitDialog()
        {
        ...
        dlg2.Create(IDD_DIALOG2, this); // where dlg2 is defined as a private CDlg2 varibale of CDlg1 in its header file
        dlg2.ShowWindow(SW_SHOW);
        ...
        }

        But this doesn't work.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        A dialog, i.e. a window shown as modal, by definition is unique within a process, as it grabs you, your mouse and keyboard until you dismiss it. If you want two dialogs, you need two processes. Or you switch to modeless windows, which aren't dialogs at all. But then other forms of the same process could also be brought to the foreground and operated on. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        S 1 Reply Last reply
        0
        • L Luc Pattyn

          A dialog, i.e. a window shown as modal, by definition is unique within a process, as it grabs you, your mouse and keyboard until you dismiss it. If you want two dialogs, you need two processes. Or you switch to modeless windows, which aren't dialogs at all. But then other forms of the same process could also be brought to the foreground and operated on. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          Luc Pattyn wrote:

          If you want two dialogs, you need two processes.

          This isn't true. It's possible and quite common for a modal dialog to have a button (or some other mechanism) which brings up another "nested" (not nested in a parent-child sense) modal dialog. Both dialogs are modal and shown at the same time although while the nested one exists the parent one is disabled.

          Steve

          L 1 Reply Last reply
          0
          • K Krauze

            I'm now coding with VC++2008. I wanna show 2 dialogs at the same time. So how to achieve it? Thanks in advance. In fact I've tried the following:

            BOOL CDlg1::OnInitDialog()
            {
            ...
            dlg2.Create(IDD_DIALOG2, this); // where dlg2 is defined as a private CDlg2 varibale of CDlg1 in its header file
            dlg2.ShowWindow(SW_SHOW);
            ...
            }

            But this doesn't work.

            X Offline
            X Offline
            Xie Jinghui
            wrote on last edited by
            #5

            define dlg2 as a member varibale of CDlg1.

            CDlg2 * m_pDlg2;

            BOOL CDlg1::OnInitDialog()
            {
            // ...
            m_pDlg2 = new CDlg2();
            m_pDlg2->Create(IDD_DIALOG2, this);
            m_pDlg2->ShowWindow(SW_SHOW);
            // ...
            }

            void CDlg1::OnDestroy()
            {
            CDialog::OnDestroy();

            // TODO: Add your message handler code here
            if(m\_pDlg2)
                delete m\_pDlg2;
            m\_pDlg2 = NULL;
            

            }

            modified on Thursday, October 28, 2010 4:17 AM

            S 1 Reply Last reply
            0
            • X Xie Jinghui

              define dlg2 as a member varibale of CDlg1.

              CDlg2 * m_pDlg2;

              BOOL CDlg1::OnInitDialog()
              {
              // ...
              m_pDlg2 = new CDlg2();
              m_pDlg2->Create(IDD_DIALOG2, this);
              m_pDlg2->ShowWindow(SW_SHOW);
              // ...
              }

              void CDlg1::OnDestroy()
              {
              CDialog::OnDestroy();

              // TODO: Add your message handler code here
              if(m\_pDlg2)
                  delete m\_pDlg2;
              m\_pDlg2 = NULL;
              

              }

              modified on Thursday, October 28, 2010 4:17 AM

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              Why bother using new and delete and the pointer m_pDlg2? In general I'd lose the new and delete (and in this case the OnDestroy handler too) and embed CDlg2 directly:

              class CDlg1 : /* Stuff removed */
              {
              // ... Stuff removed ...
                 CDlg2 m_Dlg2;
              // ... Stuff removed ...
              };
               
              BOOL CDlg1::OnShowOtherDialog()
              {
                 // ...
                 m_Dlg2.Create(IDD_DIALOG2, this);
                 m_Dlg2.ShowWindow(SW_SHOW);
                 // ...
              }

              Steve

              X 1 Reply Last reply
              0
              • S Stephen Hewitt

                Luc Pattyn wrote:

                If you want two dialogs, you need two processes.

                This isn't true. It's possible and quite common for a modal dialog to have a button (or some other mechanism) which brings up another "nested" (not nested in a parent-child sense) modal dialog. Both dialogs are modal and shown at the same time although while the nested one exists the parent one is disabled.

                Steve

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                You're right of course, however that still leaves only one accessible dialog, not what the OP wants. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                1 Reply Last reply
                0
                • K Krauze

                  I'm now coding with VC++2008. I wanna show 2 dialogs at the same time. So how to achieve it? Thanks in advance. In fact I've tried the following:

                  BOOL CDlg1::OnInitDialog()
                  {
                  ...
                  dlg2.Create(IDD_DIALOG2, this); // where dlg2 is defined as a private CDlg2 varibale of CDlg1 in its header file
                  dlg2.ShowWindow(SW_SHOW);
                  ...
                  }

                  But this doesn't work.

                  F Offline
                  F Offline
                  federico strati
                  wrote on last edited by
                  #8

                  If you don't need 2 dialogs at the same time but you need them both displayable, then you're speaking about something like a tabbed dialog: each tab will show a dialog. I've a sample of doing this at the demo app that is in the article A Standard Multithreaded Dynamic Queue. Otherwise you want to investigate modeless dialogs.

                  1 Reply Last reply
                  0
                  • S Stephen Hewitt

                    Why bother using new and delete and the pointer m_pDlg2? In general I'd lose the new and delete (and in this case the OnDestroy handler too) and embed CDlg2 directly:

                    class CDlg1 : /* Stuff removed */
                    {
                    // ... Stuff removed ...
                       CDlg2 m_Dlg2;
                    // ... Stuff removed ...
                    };
                     
                    BOOL CDlg1::OnShowOtherDialog()
                    {
                       // ...
                       m_Dlg2.Create(IDD_DIALOG2, this);
                       m_Dlg2.ShowWindow(SW_SHOW);
                       // ...
                    }

                    Steve

                    X Offline
                    X Offline
                    Xie Jinghui
                    wrote on last edited by
                    #9

                    Good advice, en,, I prefer to use pointer..

                    S 1 Reply Last reply
                    0
                    • X Xie Jinghui

                      Good advice, en,, I prefer to use pointer..

                      S Offline
                      S Offline
                      Stephen Hewitt
                      wrote on last edited by
                      #10

                      I prefer to avoid using the heap when it's not necessary: It's faster, safer and helps minimise heap fragmentation.

                      Steve

                      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