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. Creating a Modal Dialog before calling DoModal()

Creating a Modal Dialog before calling DoModal()

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 5 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.
  • O Offline
    O Offline
    ohadp
    wrote on last edited by
    #1

    I need to get a Modal-Dialog's handle (HWND) before I enter the blocking DoModal() call. The thing is the Dialog is only created inside DoModal(). Is there a way to create it in some way and then call DoModal() seperately ?

    V R 2 Replies Last reply
    0
    • O ohadp

      I need to get a Modal-Dialog's handle (HWND) before I enter the blocking DoModal() call. The thing is the Dialog is only created inside DoModal(). Is there a way to create it in some way and then call DoModal() seperately ?

      V Offline
      V Offline
      vcplusplus
      wrote on last edited by
      #2

      Why? Maybe you should try a modeless dialog. Check out this web site below. http://www.codeproject.com/dialog/gettingmodeless.asp

      O 1 Reply Last reply
      0
      • V vcplusplus

        Why? Maybe you should try a modeless dialog. Check out this web site below. http://www.codeproject.com/dialog/gettingmodeless.asp

        O Offline
        O Offline
        ohadp
        wrote on last edited by
        #3

        I need to call DoModal(), I need a Modal dialog that blocks everything else. I just need to create it before entering the modal loop.

        1 Reply Last reply
        0
        • O ohadp

          I need to get a Modal-Dialog's handle (HWND) before I enter the blocking DoModal() call. The thing is the Dialog is only created inside DoModal(). Is there a way to create it in some way and then call DoModal() seperately ?

          R Offline
          R Offline
          Ryan Binns
          wrote on last edited by
          #4

          ohadp wrote: I need to get a Modal-Dialog's handle (HWND) before I enter the blocking DoModal() call Why?? Put your code inside OnInitDialog() or OnCreate() in your dialog.

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          U O 2 Replies Last reply
          0
          • R Ryan Binns

            ohadp wrote: I need to get a Modal-Dialog's handle (HWND) before I enter the blocking DoModal() call Why?? Put your code inside OnInitDialog() or OnCreate() in your dialog.

            Ryan

            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

            U Offline
            U Offline
            User 423850
            wrote on last edited by
            #5

            if you r planning to intialize any variable then you can just write some function in the dialog class and call these just by creating the Object of the class and calling the function before calling domodal Thanx TAKE CARE

            1 Reply Last reply
            0
            • R Ryan Binns

              ohadp wrote: I need to get a Modal-Dialog's handle (HWND) before I enter the blocking DoModal() call Why?? Put your code inside OnInitDialog() or OnCreate() in your dialog.

              Ryan

              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

              O Offline
              O Offline
              ohadp
              wrote on last edited by
              #6

              This specific dialog doesn't need to knwo to do special stuff in it's OnInitDialog(). What I did eventually was send it a pointer to : class CRunner { public: virtual void Run() = 0; }; but I'm still looking for a better way, as in externaly creating the dialog, accessing it's HWND, then entering the Modal-Loop. Does someone have an example of creating the dialog Modeless, and then entering some sort of message-pumping loop that would make it modal ? thanks

              A 1 Reply Last reply
              0
              • O ohadp

                This specific dialog doesn't need to knwo to do special stuff in it's OnInitDialog(). What I did eventually was send it a pointer to : class CRunner { public: virtual void Run() = 0; }; but I'm still looking for a better way, as in externaly creating the dialog, accessing it's HWND, then entering the Modal-Loop. Does someone have an example of creating the dialog Modeless, and then entering some sort of message-pumping loop that would make it modal ? thanks

                A Offline
                A Offline
                Alvaro Mendez
                wrote on last edited by
                #7

                I don't have the exact code, but you can do something like this:

                CMyDlg dlg = this;

                // Create it modeless
                dlg.Create(dlg.IDD);

                // Get your HWND
                HWND hWnd = dlg.m_hWnd

                // Modalize it
                EnableWindow(FALSE); // disable parent
                dlg.CenterWindow(); // center dlg
                dlg.ShowWindow(SW_SHOW); // show dlg
                int nResult = dlg.RunModalLoop(MLF_SHOWONIDLE); // wait for it close
                dlg.DestroyWindow(); // destroy dlg
                EnableWindow(TRUE); // reenable parent

                You can also check out MFC's code for DoModal. Regards, Alvaro


                Hey! It compiles! Ship it.

                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