how to add "are you sure?"

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

how to add "are you sure?"

Post by Jacek Poplawski »

Is there a predefined way to add "are you sure?" dialog before quitting?
I can't find it anywhere.
asadilan
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Jul 27, 2010 10:42 pm

Re: how to add "are you sure?"

Post by asadilan »

wxMessageDialog
wxMessageBox
Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

Re: how to add "are you sure?"

Post by Jacek Poplawski »

yes I know, but I asked for something predefined :)
spedgenius
Experienced Solver
Experienced Solver
Posts: 66
Joined: Thu Dec 15, 2005 8:16 pm

Re: how to add "are you sure?"

Post by spedgenius »

if you looked at the documentation for wxMessageBox that asadilan suggested you would have seen that you could do something like this

Code: Select all

    int answer = wxMessageBox("Quit program?", "Confirm",
                              wxYES_NO | wxCANCEL, main_frame);
    
    if (answer == wxYES)
        main_frame->Close();
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.
Radek
Super wx Problem Solver
Super wx Problem Solver
Posts: 286
Joined: Sun Sep 11, 2011 7:17 am

Re: how to add "are you sure?"

Post by Radek »

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().
Post Reply