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 Dialog Box

Modeless Dialog Box

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

    I need to create a modeless dialog but when I use Create() the dialog quickly appears and disappears. As an expirement I tried cerating a quick dialog-based app using the C++ wizard and created a button that brings up the about box (as created by the wizard) without using DoModal. Does anyone know how to do this please? It's quite frustrating.

    P B 2 Replies Last reply
    0
    • M mmica

      I need to create a modeless dialog but when I use Create() the dialog quickly appears and disappears. As an expirement I tried cerating a quick dialog-based app using the C++ wizard and created a button that brings up the about box (as created by the wizard) without using DoModal. Does anyone know how to do this please? It's quite frustrating.

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      If you could post the code how you are creating the modeless dialog box may be that would pin point the prob. any ways here how i would create the modeless dialog.

      CMydialog *pDialog;
      pDialog = new CMydialog;
      pDialog->Create(CMyDialog::IDD);
      pDialog->ShowWindow(SW_SHOW);


      MSN Messenger. prakashnadar@msn.com

      M 1 Reply Last reply
      0
      • P Prakash Nadar

        If you could post the code how you are creating the modeless dialog box may be that would pin point the prob. any ways here how i would create the modeless dialog.

        CMydialog *pDialog;
        pDialog = new CMydialog;
        pDialog->Create(CMyDialog::IDD);
        pDialog->ShowWindow(SW_SHOW);


        MSN Messenger. prakashnadar@msn.com

        M Offline
        M Offline
        mmica
        wrote on last edited by
        #3

        Your code works fine. It was exactly the same as mine only you used a pointer to a dialog and I used an instance directly. Doesn't really make much sense to me but as long as it works, I'm happy right now ;-) Thanks for your help.

        P D 2 Replies Last reply
        0
        • M mmica

          I need to create a modeless dialog but when I use Create() the dialog quickly appears and disappears. As an expirement I tried cerating a quick dialog-based app using the C++ wizard and created a button that brings up the about box (as created by the wizard) without using DoModal. Does anyone know how to do this please? It's quite frustrating.

          B Offline
          B Offline
          bilal78
          wrote on last edited by
          #4

          well your problem might be as it seems from the description : You are creating the dialog variable in the OnButtonXXX() function, and when you create the modeless dialog, means CreateDialog returns at that very moment, and so does your funtion ( after calling ::ShowWindow(...)). And when your function ends, scope of your dialog ends (this is the reason for flashing, it creates, then ShowWindow() gets called and then scope ends. :( ), Try to make the variable outside the function (class variable or global), and try the same code, hopefully it will work. Regards, Bilal Anjum

          M 1 Reply Last reply
          0
          • M mmica

            Your code works fine. It was exactly the same as mine only you used a pointer to a dialog and I used an instance directly. Doesn't really make much sense to me but as long as it works, I'm happy right now ;-) Thanks for your help.

            P Offline
            P Offline
            Prakash Nadar
            wrote on last edited by
            #5

            But do remember that the dialog object is created using new so there should be a corresponding delete as well. usally the modeless dialogs are self deleteing, you put

            delete this

            in OnDestroy event.


            MSN Messenger. prakashnadar@msn.com

            D 1 Reply Last reply
            0
            • B bilal78

              well your problem might be as it seems from the description : You are creating the dialog variable in the OnButtonXXX() function, and when you create the modeless dialog, means CreateDialog returns at that very moment, and so does your funtion ( after calling ::ShowWindow(...)). And when your function ends, scope of your dialog ends (this is the reason for flashing, it creates, then ShowWindow() gets called and then scope ends. :( ), Try to make the variable outside the function (class variable or global), and try the same code, hopefully it will work. Regards, Bilal Anjum

              M Offline
              M Offline
              mmica
              wrote on last edited by
              #6

              Thanks... That makes perfect sense :-)

              1 Reply Last reply
              0
              • P Prakash Nadar

                But do remember that the dialog object is created using new so there should be a corresponding delete as well. usally the modeless dialogs are self deleteing, you put

                delete this

                in OnDestroy event.


                MSN Messenger. prakashnadar@msn.com

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                Mr.Prakash wrote: ...in OnDestroy event. Actually, the this pointer should be deleted in PostNcDestroy().


                "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                P 1 Reply Last reply
                0
                • M mmica

                  Your code works fine. It was exactly the same as mine only you used a pointer to a dialog and I used an instance directly. Doesn't really make much sense to me but as long as it works, I'm happy right now ;-) Thanks for your help.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Don't forget to override the OnCancel() member function and call DestroyWindow() from within it. Don’t call the base class CDialog::OnCancel(), because it calls EndDialog(), which will make the dialog box invisible but will not destroy it.


                  "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                  1 Reply Last reply
                  0
                  • D David Crow

                    Mr.Prakash wrote: ...in OnDestroy event. Actually, the this pointer should be deleted in PostNcDestroy().


                    "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                    P Offline
                    P Offline
                    Prakash Nadar
                    wrote on last edited by
                    #9

                    yeah correct. ;P


                    MSN Messenger. prakashnadar@msn.com

                    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