// Build: g++ this.cpp -std=gnu++11 $(wx-config --cxxflags --libs core,base)
#include <wx/wx.h>
class CApp : public wxApp
{
public:
bool OnInit() {
// Create the main frame.
wxFrame * frame = new wxFrame(NULL, wxID_ANY, wxT("demo"));
// Add the menubar
wxMenu * menus[] = {new wxMenu, new wxMenu};
wxString labels[] = {wxT("&File"), wxT("&Help")};
frame->wxFrame::SetMenuBar(new wxMenuBar(2, menus, labels));
menus[0]->Append(wxID_EXIT);
// Bind an event handling method for menu item wxID_EXIT.
this->Bind(wxEVT_MENU, [frame](wxCommandEvent &)->void{
frame->Close();
/* 1. method wxWindow::Close
* 2. event type wxEVT_CLOSE_WINDOW
* 3. method wxTopLevelWindow::OnCloseWindow
* 4. method wxTopLevelWindow::Destroy (overriding wxWindow::Destroy)
* 5. op delete
*/
}, wxID_EXIT);
// Enter the message loop.
frame->Centre(wxBOTH);
frame->Show(true);
return true;
}
int OnExit() {
wxMessageBox("Closing the application", wxEmptyString, wxOK | wxICON_INFORMATION);
return this->wxApp::OnExit();
}
};
wxDECLARE_APP(CApp);
wxIMPLEMENT_APP(CApp);
很多答案可以通過首先搜索互聯網或StackOverflow找到之前發佈在這裏。 –