How to intercept close event Topic is solved

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
modoran
Knows some wx things
Knows some wx things
Posts: 47
Joined: Tue Mar 23, 2010 1:31 pm
Location: Romania
Contact:

How to intercept close event

Post by modoran »

This is probably very trivial, but i could not find the answer in the docs :(
How to intercept close event of the main window ? Basically i want to show a confirmation dialog before my app is closed, if the user confirm then proceed, if not then do nothing
jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche »

look at wxCloseEvent.

If you use event table :

Code: Select all

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
   EVT_CLOSE(MyFrame::OnFrameClose)
END_EVENT_TABLE()

void MyFrame::OnFrameClose(wxCloseEvent& event)
{
   Destroy();
}
Jérémie
Debster
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sat Aug 20, 2005 6:01 pm

Post by Debster »

try handling the "wxCloseEvent" event for the main window. In your own handling method simply show the dialog and when the user clicks ok, call the destroy method. Otherwise do nothing and the main window remains working.
modoran
Knows some wx things
Knows some wx things
Posts: 47
Joined: Tue Mar 23, 2010 1:31 pm
Location: Romania
Contact:

Post by modoran »

Problem solved, thank you both.
Post Reply