But what if he wants to cancel the action and do nothing? Usually you would have a Cancel and OK/Apply button and call EndModal(wxID_OK) only when the user hits the OK button. In all other cases (Cancel button, Window close icon, or pressing ESC), you'd call EndModal(wxID_CANCEL). The value you pass to EndModal() will be the return value of the ShowModal() call.Wanderer82 wrote: ↑Mon Jul 19, 2021 10:17 pm Well, for what reason should I evaluate the return value of ShowModal()? The user has to close the dialog himself. In the dialog he can put products into the basket and when he's finished, he closes the dialog window.
Desperate - How to close wxDialog?
-
- Moderator
- Posts: 19163
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
Re: Desperate - How to close wxDialog?
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 675
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Desperate - How to close wxDialog?
First of all... I have different groups of products. The dialog we are talking about here, shows the products for one group. In this window I put the "Apply" button for each product that goes inside the basket. If the user wants to take one or all of them out, he has to Cancel it for each product. If he wants to choose more from another group, he closes the window by just clicking on the cross in the top right.
But I'm not yet at the end of my design here, it's just how it works so far. Normally, if you put different items in a basket, you can't cancel the basket in the same dialog or webpage where you put the product into the basket. You go to the basket first and then empty it or delete individual items. But I'll keep this in mind if I need another functionality.
But when we're talking about EndModal(). Until now I used Close(). So I'll replace all Close() wirh EndModal(). I think that's the right way to do. But I wonder: In my dialog I have no special button to close it. And in the deconstructor - which I guess is called when the user clicks the cross - there is no EndModal(). Why is that? Is EndModal() called anyway when the deconstructor is called?
But I'm not yet at the end of my design here, it's just how it works so far. Normally, if you put different items in a basket, you can't cancel the basket in the same dialog or webpage where you put the product into the basket. You go to the basket first and then empty it or delete individual items. But I'll keep this in mind if I need another functionality.
But when we're talking about EndModal(). Until now I used Close(). So I'll replace all Close() wirh EndModal(). I think that's the right way to do. But I wonder: In my dialog I have no special button to close it. And in the deconstructor - which I guess is called when the user clicks the cross - there is no EndModal(). Why is that? Is EndModal() called anyway when the deconstructor is called?
-
- Part Of The Furniture
- Posts: 7481
- Joined: Sat Apr 16, 2005 7:22 am
- Location: USA, Ukraine
Re: Desperate - How to close wxDialog?
Hi,
Is the dialog have 2 buttons or just one?
Thank you.
Is the dialog have 2 buttons or just one?
Thank you.
-
- Moderator
- Posts: 19163
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
Re: Desperate - How to close wxDialog?
EndModal() just exits the modal loop and gives control back to the calling code (= returns from ShowModal()). Destroying the dialog is a different issue. If the dialog was created on the stack, destruction happens when it goes out of scope.Wanderer82 wrote: ↑Mon Jul 19, 2021 10:44 pm And in the deconstructor - which I guess is called when the user clicks the cross - there is no EndModal(). Why is that? Is EndModal() called anyway when the deconstructor is called?
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 675
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Desperate - How to close wxDialog?
The dialog has a button for each product (to put it in the basket). There are no other / general buttons to close the window or apply changes etc. Only the standard "cross" to close the window is there.
-
- Ultimate wxWidgets Guru
- Posts: 675
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Desperate - How to close wxDialog?
So, calling EndModal() means that the dialog goes out of scope, right?doublemax wrote: ↑Tue Jul 20, 2021 5:06 amEndModal() just exits the modal loop and gives control back to the calling code (= returns from ShowModal()). Destroying the dialog is a different issue. If the dialog was created on the stack, destruction happens when it goes out of scope.Wanderer82 wrote: ↑Mon Jul 19, 2021 10:44 pm And in the deconstructor - which I guess is called when the user clicks the cross - there is no EndModal(). Why is that? Is EndModal() called anyway when the deconstructor is called?
-
- Super wx Problem Solver
- Posts: 474
- Joined: Wed Jul 29, 2020 6:06 pm
- Location: NRW, Germany
Re: Desperate - How to close wxDialog?
No. "Going out of scope" means something different. A local variable goes "out of scope" when the code block in which it was defined, ends. At that time the variable will be destroyed.So, calling EndModal() means that the dialog goes out of scope, right?
Code: Select all
void foo()
{
if( condition == true )
{
wxString s = "hello";
}
// can't access variable "s" here. It's "out of scope" and already destroyed.
}