#include <wx\wx.h> class Form :public wxApp { wxFrame*window; public: bool OnInit() { window = new wxFrame(nullptr, -1, "Form", wxPoint(100, 100), wxSize(840, 640)); window->Centre(wxBOTH); window->Show(true); return true; } ~Form() { wxMessageBox("Bye", "Info"); } }; class Win :public wxApp { wxFrame*window; public: bool OnInit() { window = new wxFrame(nullptr, -1, "hi", wxPoint(100, 100), wxSize(840, 640)); window->Centre(wxBOTH); window->Show(true); Form *form = new Form(); form->OnInit(); return true; } void form_close() { wxMessageBox("Form closed", "Info"); } }; IMPLEMENT_APP(Win); 

how to track the closing of the Form window in Win

  • Like for wxwidgets - Arkady

1 answer 1

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):

  1. About events and their processing - Events and Event Handling
  2. Window Removal - Window Deletion
  3. WxWidgets - wxApp Applications

I advise you also to pay attention to the examples from the samples folder - they are very useful.