Return From DoModal with RadioButton
-
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
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.
-
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
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
-
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
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
-
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
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 WrapperBest Wishes, -David Delaune
-
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 WrapperBest Wishes, -David Delaune
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
-
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
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
-
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
-
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
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
-
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
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!
-
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!
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.