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. Modeless modal CDialog

Modeless modal CDialog

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionlearning
9 Posts 4 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.
  • R Offline
    R Offline
    Rage
    wrote on last edited by
    #1

    Hi CPians! I have a MFC Dlg app, that should be able to fire up an unlimited amount of dialogs when clicking on one button (e.g. one dialog per click). In the OnClickButton handler, if i run my code that way :

    CMyDialog mydlg;
    mydlg.DoModal();

    the main dialog freezes after the first child dialog is started (of course, that's the way modal dialog are meant to work). If I do it this way :

    CMyDialog mydlg;
    mydlg.Create(...);
    mydlg.Show();

    the dialog is closed as soon as I leave the OnClickButton, that is almost instantly, since mydlg is a local variable in that function. So what I intend to do is launch the dialog modal in a working thread, but this semms to be a bit paradoxical to me. Is it any better solution, or is this the ultimate one ? Thanks a lot ~RaGE();

    M H E 3 Replies Last reply
    0
    • R Rage

      Hi CPians! I have a MFC Dlg app, that should be able to fire up an unlimited amount of dialogs when clicking on one button (e.g. one dialog per click). In the OnClickButton handler, if i run my code that way :

      CMyDialog mydlg;
      mydlg.DoModal();

      the main dialog freezes after the first child dialog is started (of course, that's the way modal dialog are meant to work). If I do it this way :

      CMyDialog mydlg;
      mydlg.Create(...);
      mydlg.Show();

      the dialog is closed as soon as I leave the OnClickButton, that is almost instantly, since mydlg is a local variable in that function. So what I intend to do is launch the dialog modal in a working thread, but this semms to be a bit paradoxical to me. Is it any better solution, or is this the ultimate one ? Thanks a lot ~RaGE();

      M Offline
      M Offline
      Monty2
      wrote on last edited by
      #2

      Rage wrote: CMyDialog mydlg;mydlg.Create(...);mydlg.Show(); the dialog is closed as soon as I leave the onclickButton, that is almost instantly, since mydlg is a local variable in that function. why don't you declare CMyDialog as member variable or global variable or static variable, that will work exactly as you intend. C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg

      R 2 Replies Last reply
      0
      • R Rage

        Hi CPians! I have a MFC Dlg app, that should be able to fire up an unlimited amount of dialogs when clicking on one button (e.g. one dialog per click). In the OnClickButton handler, if i run my code that way :

        CMyDialog mydlg;
        mydlg.DoModal();

        the main dialog freezes after the first child dialog is started (of course, that's the way modal dialog are meant to work). If I do it this way :

        CMyDialog mydlg;
        mydlg.Create(...);
        mydlg.Show();

        the dialog is closed as soon as I leave the OnClickButton, that is almost instantly, since mydlg is a local variable in that function. So what I intend to do is launch the dialog modal in a working thread, but this semms to be a bit paradoxical to me. Is it any better solution, or is this the ultimate one ? Thanks a lot ~RaGE();

        H Offline
        H Offline
        Hans Ruck
        wrote on last edited by
        #3

        You may use:

        CMyDialog *pmydlg=new CMyDialog;
        pmydlg->Create(...);
        pmydlg->Show();

        to create the modeless dialog who's PostNcDestroy should look like this:

        void CMyDialog::PostNcDestroy()
        {
        // your stuff...
        CDialog::PostNcDestroy();
        delete this;
        }

        rechi

        R 1 Reply Last reply
        0
        • R Rage

          Hi CPians! I have a MFC Dlg app, that should be able to fire up an unlimited amount of dialogs when clicking on one button (e.g. one dialog per click). In the OnClickButton handler, if i run my code that way :

          CMyDialog mydlg;
          mydlg.DoModal();

          the main dialog freezes after the first child dialog is started (of course, that's the way modal dialog are meant to work). If I do it this way :

          CMyDialog mydlg;
          mydlg.Create(...);
          mydlg.Show();

          the dialog is closed as soon as I leave the OnClickButton, that is almost instantly, since mydlg is a local variable in that function. So what I intend to do is launch the dialog modal in a working thread, but this semms to be a bit paradoxical to me. Is it any better solution, or is this the ultimate one ? Thanks a lot ~RaGE();

          E Offline
          E Offline
          Empty1981
          wrote on last edited by
          #4

          in your button event,you should like this: CMyDialog mydlg=new CMyDialog; mydlg.Create(...); mydlg.Show(); in the class of CMyDialog you should add a function CMyDialog::PostNCDestroy() { delete this; }

          R 1 Reply Last reply
          0
          • M Monty2

            Rage wrote: CMyDialog mydlg;mydlg.Create(...);mydlg.Show(); the dialog is closed as soon as I leave the onclickButton, that is almost instantly, since mydlg is a local variable in that function. why don't you declare CMyDialog as member variable or global variable or static variable, that will work exactly as you intend. C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg

            R Offline
            R Offline
            Rage
            wrote on last edited by
            #5

            mailMonty wrote: why don't you declare CMyDialog as member variable or global variable or static variable, that will work exactly as you intend. Because I do not know how many of them I will need (see in my post, you fire up a dlg every time you click on a button). So declaring them as global would require a dynamical global array of dlgs :~ ~RaGE();

            1 Reply Last reply
            0
            • H Hans Ruck

              You may use:

              CMyDialog *pmydlg=new CMyDialog;
              pmydlg->Create(...);
              pmydlg->Show();

              to create the modeless dialog who's PostNcDestroy should look like this:

              void CMyDialog::PostNcDestroy()
              {
              // your stuff...
              CDialog::PostNcDestroy();
              delete this;
              }

              rechi

              R Offline
              R Offline
              Rage
              wrote on last edited by
              #6

              Thanks rechi, I had already thought about something like this, i missed the existence of PostNcDestroy. Thanks again. ~RaGE();

              H 1 Reply Last reply
              0
              • E Empty1981

                in your button event,you should like this: CMyDialog mydlg=new CMyDialog; mydlg.Create(...); mydlg.Show(); in the class of CMyDialog you should add a function CMyDialog::PostNCDestroy() { delete this; }

                R Offline
                R Offline
                Rage
                wrote on last edited by
                #7

                coolaka wrote: CMyDialog mydlg=new CMyDialog; mydlg.Create(...); mydlg.Show(); Yep, even better with a pointer (see rechi's post) IMO. Thanks a lot for your help. ~RaGE();

                1 Reply Last reply
                0
                • M Monty2

                  Rage wrote: CMyDialog mydlg;mydlg.Create(...);mydlg.Show(); the dialog is closed as soon as I leave the onclickButton, that is almost instantly, since mydlg is a local variable in that function. why don't you declare CMyDialog as member variable or global variable or static variable, that will work exactly as you intend. C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg

                  R Offline
                  R Offline
                  Rage
                  wrote on last edited by
                  #8

                  mailMonty wrote: C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg very good sig :-D ~RaGE();

                  1 Reply Last reply
                  0
                  • R Rage

                    Thanks rechi, I had already thought about something like this, i missed the existence of PostNcDestroy. Thanks again. ~RaGE();

                    H Offline
                    H Offline
                    Hans Ruck
                    wrote on last edited by
                    #9

                    Rage wrote: Thanks A pleasure :cool: Rage wrote: i missed the existence of PostNcDestroy I knew it... ;P rechi

                    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