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. Return From DoModal with RadioButton

Return From DoModal with RadioButton

Scheduled Pinned Locked Moved C / C++ / MFC
11 Posts 3 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.
  • F ForNow

    Hi IS there a way to return from DoModal without having a PUSH BUTTON with the value of IDOK ,IDCACEL or IDABORT I would like to have 3 radio buttons specifying 3 choice and return the value of one of those to DoModal thanks

    V Offline
    V Offline
    Victor Nijegorodov
    wrote on last edited by
    #2

    ForNow wrote:

    IS there a way to return from DoModal without having a PUSH BUTTON with the value of IDOK ,IDCACEL or IDABORT

    Yes. Just press the Enter button.

    1 Reply Last reply
    0
    • F ForNow

      Hi IS there a way to return from DoModal without having a PUSH BUTTON with the value of IDOK ,IDCACEL or IDABORT I would like to have 3 radio buttons specifying 3 choice and return the value of one of those to DoModal thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #3

      Hi,

      ForNow wrote:

      Hi Is there a way to return from DoModal without having a PUSH BUTTON with the value of IDOK?

      Yes. You would need to call the [EndDialog function](https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enddialog) with the second argument set to the ID of your radio button. If you are not using Windows API and are using MFC instead... you would call [CDialog::EndDialog](https://docs.microsoft.com/en-us/cpp/mfc/reference/cdialog-class?view=vs-2019#enddialog) Best Wishes, -David Delaune

      F 1 Reply Last reply
      0
      • L Lost User

        Hi,

        ForNow wrote:

        Hi Is there a way to return from DoModal without having a PUSH BUTTON with the value of IDOK?

        Yes. You would need to call the [EndDialog function](https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enddialog) with the second argument set to the ID of your radio button. If you are not using Windows API and are using MFC instead... you would call [CDialog::EndDialog](https://docs.microsoft.com/en-us/cpp/mfc/reference/cdialog-class?view=vs-2019#enddialog) Best Wishes, -David Delaune

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #4

        I thought enddialog takes the value returned from DoModal How can I pass return value to DoModal without one the predefined ways/values Microsoft is forcing me I for instance would like to return the ID of a radio button which tell me which one of the options the user selected

        L 1 Reply Last reply
        0
        • F ForNow

          I thought enddialog takes the value returned from DoModal How can I pass return value to DoModal without one the predefined ways/values Microsoft is forcing me I for instance would like to return the ID of a radio button which tell me which one of the options the user selected

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #5

          ForNow wrote:

          I thought enddialog takes the value returned from DoModal

          You have that backwards... DoModal() receives the return value from EndDialog()

          ForNow wrote:

          How can I pass return value to DoModal without one the predefined ways/values Microsoft is forcing me

          EndDialog(YourWindowHandle,YOUR_RADIO_ID); //If you're using Windows API
          EndDialog(YOUR_RADIO_ID); //If you're using MFC Wrapper

          Best Wishes, -David Delaune

          F 1 Reply Last reply
          0
          • L Lost User

            ForNow wrote:

            I thought enddialog takes the value returned from DoModal

            You have that backwards... DoModal() receives the return value from EndDialog()

            ForNow wrote:

            How can I pass return value to DoModal without one the predefined ways/values Microsoft is forcing me

            EndDialog(YourWindowHandle,YOUR_RADIO_ID); //If you're using Windows API
            EndDialog(YOUR_RADIO_ID); //If you're using MFC Wrapper

            Best Wishes, -David Delaune

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #6

            Thanks My DoModal is being called from My CMainFrame once returning to DoModal via EndDialog the Dialog box is destroyed but the class/object is still around ( I created the modal Dialog on the stack ) so the data in the class is still available until I exit the CMainFrame Routine Also the only way to have a bad return code from UpdateData is to call pDx->fail which has the side effect of an exception which I would have to delete. if everything is okay I just call EnDialog notifying the CMainFrame which called DoModal of my selection Thanks

            L 1 Reply Last reply
            0
            • F ForNow

              Thanks My DoModal is being called from My CMainFrame once returning to DoModal via EndDialog the Dialog box is destroyed but the class/object is still around ( I created the modal Dialog on the stack ) so the data in the class is still available until I exit the CMainFrame Routine Also the only way to have a bad return code from UpdateData is to call pDx->fail which has the side effect of an exception which I would have to delete. if everything is okay I just call EnDialog notifying the CMainFrame which called DoModal of my selection Thanks

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #7

              Hi, I am happy to hear that you have it working. :)

              ForNow wrote:

              Also the only way to have a bad return code from UpdateData is to call pDx->fail which has the side effect of an exception which I would have to delete. if everything is okay I just call EndDialog notifying the CMainFrame which called DoModal of my selection

              OK, let me know if you have any problems here. But from what you've described it sounds like the desired outcome. Best Wishes, -David Delaune

              F 1 Reply Last reply
              0
              • L Lost User

                Hi, I am happy to hear that you have it working. :)

                ForNow wrote:

                Also the only way to have a bad return code from UpdateData is to call pDx->fail which has the side effect of an exception which I would have to delete. if everything is okay I just call EndDialog notifying the CMainFrame which called DoModal of my selection

                OK, let me know if you have any problems here. But from what you've described it sounds like the desired outcome. Best Wishes, -David Delaune

                F Offline
                F Offline
                ForNow
                wrote on last edited by
                #8

                only one Issue UpdateData seems to always return TRUE even if I call pDX->fail maybe I should set a global BOOL in my Modal Dialog Class and bypass checking return code from UpdateData Thanks

                L V 2 Replies Last reply
                0
                • F ForNow

                  only one Issue UpdateData seems to always return TRUE even if I call pDX->fail maybe I should set a global BOOL in my Modal Dialog Class and bypass checking return code from UpdateData Thanks

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #9

                  ForNow wrote:

                  only one Issue UpdateData seems to always return TRUE

                  That means UpdateData() succeeded. Can you explain to me why you need UpdateData to fail?

                  ForNow wrote:

                  even if I call pDX->fail

                  With my experience I am going to make a strong inference that your pDX variable is a pointer to a [CDataExchange object](https://docs.microsoft.com/en-us/cpp/mfc/reference/cdataexchange-class?view=vs-2019). Can you explain to me why you need this to fail? If this fails a runtime error will be thrown... I can't even think of a valid reason you would want this. The source for UpdateData() is inside wincore.cpp and you will find that the UpdateData() function constructs a new CDataExchange object and attaches it to your Cwnd object and performs DDX through there. In other words... your line of code inside your class:

                  pDX->Fail(); // This fails because it's a pointer to another CDataExchange object.

                  You should to open [Your Visual Studio Path]\VC\atlmfc\src\mfc\wincore.cpp and scroll down to the Updatedata() implementation where you will immediately understand why UpdateData() always returns TRUE; It creates a new CDataExchange object inside the function. You cannot force UpdateData() to fail by manipulating an external object. Best Wishes, -David Delaune

                  1 Reply Last reply
                  0
                  • F ForNow

                    only one Issue UpdateData seems to always return TRUE even if I call pDX->fail maybe I should set a global BOOL in my Modal Dialog Class and bypass checking return code from UpdateData Thanks

                    V Offline
                    V Offline
                    Victor Nijegorodov
                    wrote on last edited by
                    #10

                    ForNow wrote:

                    only one Issue UpdateData seems to always return TRUE even if I call pDX->fail maybe I should set a global BOOL in my Modal Dialog Class and bypass checking return code from UpdateData

                    Why do you need the "return code from UpdateData"? Why do you need the UpdateData at all? There was a great essay about [Avoid UpdateData](http://www.flounder.com/updatedata.htm) of Joe Newcomer. I'd recommend you to check it out!

                    L 1 Reply Last reply
                    0
                    • V Victor Nijegorodov

                      ForNow wrote:

                      only one Issue UpdateData seems to always return TRUE even if I call pDX->fail maybe I should set a global BOOL in my Modal Dialog Class and bypass checking return code from UpdateData

                      Why do you need the "return code from UpdateData"? Why do you need the UpdateData at all? There was a great essay about [Avoid UpdateData](http://www.flounder.com/updatedata.htm) of Joe Newcomer. I'd recommend you to check it out!

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      Hi Victor, I've been meaning to tell you that I am happy to see you have finally moved over here from CodeGuru. I followed Chris over to his new site some 18+ years ago soon after Zafir Anjum sold codeguru and I rarely go back to the old site anymore.

                      Victor Nijegorodov wrote:

                      Why do you need the UpdateData at all? There was a great essay about Avoid UpdateData of Joe Newcomer. I'd recommend you to check it out!

                      Actually in this case he may need to call UpdateData() because he is bypassing both the CWnd::OnOk and also exiting the dialog with EndDialog(SOME_RADIO_ID); With that knowledge go and read the final two paragraphs in the debate between Doug Harrison and Dr. Newcomer. If we are going to suggest that the poster "ForNow" avoid using UpdateData() then we need to ensure that he is using control variables. Best Wishes, -David Delaune P.S. I haven't used MFC in nearly 10 years, not sure why I even remember these things.

                      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