Is there a predefined way to add "are you sure?" dialog before quitting?
I can't find it anywhere.
how to add "are you sure?"
-
- Knows some wx things
- Posts: 38
- Joined: Mon Jun 20, 2011 12:03 pm
Re: how to add "are you sure?"
wxMessageDialog
wxMessageBox
wxMessageBox
-
- Knows some wx things
- Posts: 38
- Joined: Mon Jun 20, 2011 12:03 pm
Re: how to add "are you sure?"
yes I know, but I asked for something predefined
-
- Experienced Solver
- Posts: 66
- Joined: Thu Dec 15, 2005 8:16 pm
Re: how to add "are you sure?"
if you looked at the documentation for wxMessageBox that asadilan suggested you would have seen that you could do something like this
It is a convenience function that shows a wxMessageDialog with yes and no buttons and returns a value based on what the user selects. You can't get much easier than that.
Code: Select all
int answer = wxMessageBox("Quit program?", "Confirm",
wxYES_NO | wxCANCEL, main_frame);
if (answer == wxYES)
main_frame->Close();
Re: how to add "are you sure?"
Sure, but where "are you sure" should be called from.
The event you need to catch is wxEVT_CLOSE_WINDOW. There was a thread a few days ago, which solved the same problem:
http://forums.wxwidgets.org/viewtopic.php?f=1&t=33837
The event can be (not always!) vetoed. Thus, "if you aren't sure" then check CanVeto() and if you can Veto() then Veto(). The event is sent from Close(), do not call Close() from the handler. Call Destroy().
The event you need to catch is wxEVT_CLOSE_WINDOW. There was a thread a few days ago, which solved the same problem:
http://forums.wxwidgets.org/viewtopic.php?f=1&t=33837
The event can be (not always!) vetoed. Thus, "if you aren't sure" then check CanVeto() and if you can Veto() then Veto(). The event is sent from Close(), do not call Close() from the handler. Call Destroy().