First you need to figure out which event you want to track - closing the window (in your case, represented by an instance of the wxFrame class) or closing the entire application.
The first one is of type wxEVT_CLOSE_WINDOW and will occur when the user clicks the close button or is created programmatically, after calling the Close / 1 function.
To process it, you can use the event table or use wxEvtHandler :: Bind <> () , if your compiler can use C ++ 11 features. Example:
frame->Bind(wxEVT_CLOSE_WINDOW, [&](wxCloseEvent& event) { if ( event.CanVeto()) { if ( wxMessageBox("Уверены что хотите закрыть?", "Подтвердите действие", wxICON_QUESTION | wxYES_NO) != wxYES ) { event.Veto(); return; } } event.Skip();//вызовет Destroy/0 по-умолчанию });
the same can be done in the frame constructor:
Bind(wxEVT_CLOSE_WINDOW, [&](wxCloseEvent& event) { if ( event.CanVeto()) { if ( wxMessageBox("Уверены что хотите закрыть?", "Подтвердите действие", wxICON_QUESTION | wxYES_NO) != wxYES ) { event.Veto(); return; } } event.Skip(); });
If about the second, then to perform operations when the application is closed (it runs automatically after all windows have been destroyed [talking about a normal GUI application]), it is enough to overload the OnExit / 0 function. If OnInit / 0 is unsuccessful, the OnExit / 0 function is not called.
As usual, you can read the details in the documentation (it is in English):
- About events and their processing - Events and Event Handling
- Window Removal - Window Deletion
- WxWidgets - wxApp Applications
I advise you also to pay attention to the examples from the samples folder - they are very useful.