Created
June 11, 2019 13:51
-
-
Save johnfredcee/93a6eb8352cd3c62fd52b09dc7493564 to your computer and use it in GitHub Desktop.
wxWidgets Hello World
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <wx/wxprec.h> | |
| #ifndef WX_PRECOMP | |
| #include <wx/wx.h> | |
| #endif | |
| class App : public wxApp | |
| { | |
| public: | |
| bool OnInit(); | |
| }; | |
| class Frame : public wxFrame | |
| { | |
| public: | |
| Frame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
| private: | |
| void OnExit(wxCommandEvent& event); | |
| void OnAbout(wxCommandEvent& event); | |
| void OnHello(wxCommandEvent& event); | |
| wxDECLARE_EVENT_TABLE(); | |
| }; | |
| enum { ID_Hello = 1 }; | |
| // clang-format off | |
| wxBEGIN_EVENT_TABLE(Frame, wxFrame) | |
| EVT_MENU(ID_Hello, Frame::OnHello) | |
| EVT_MENU(wxID_EXIT, Frame::OnExit) | |
| EVT_MENU(wxID_ABOUT, Frame::OnAbout) | |
| wxEND_EVENT_TABLE() | |
| wxIMPLEMENT_APP(App); | |
| // clang-format on | |
| bool App::OnInit() | |
| { | |
| Frame* frame = new Frame("Hello World", wxPoint(50, 50), wxSize(450, 340)); | |
| frame->Show(true); | |
| return true; | |
| } | |
| Frame::Frame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
| : wxFrame(NULL, wxID_ANY, title, pos, size) | |
| { | |
| wxMenu* menuFile = new wxMenu(); | |
| menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", | |
| "Help string show in status bar"); | |
| menuFile->AppendSeparator(); | |
| menuFile->Append(wxID_EXIT); | |
| wxMenu* menuHelp = new wxMenu(); | |
| menuHelp->Append(wxID_ABOUT); | |
| wxMenuBar* menuBar = new wxMenuBar(); | |
| menuBar->Append(menuFile, "&File"); | |
| menuBar->Append(menuHelp, "&Help"); | |
| SetMenuBar(menuBar); | |
| CreateStatusBar(); | |
| SetStatusText("Welcome to wxWidgets!"); | |
| } | |
| void Frame::OnExit(wxCommandEvent& event) { Close(true); } | |
| void Frame::OnAbout(wxCommandEvent& event) | |
| { | |
| wxMessageBox("This is a wxWidgets' Hello world example", "About Hello World", | |
| wxOK | wxICON_INFORMATION); | |
| } | |
| void Frame::OnHello(wxCommandEvent& event) | |
| { | |
| wxLogMessage("Hello World from wxWidgets!"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment