Skip to content

Instantly share code, notes, and snippets.

@jgcoded
Created May 2, 2017 18:10
Show Gist options
  • Save jgcoded/0f5f0d9ce1d6ec46bcb7fe35504715a5 to your computer and use it in GitHub Desktop.
Save jgcoded/0f5f0d9ce1d6ec46bcb7fe35504715a5 to your computer and use it in GitHub Desktop.
Sample WxWidgets 3.0.3 Hello World application
#include <wx/app.h>
#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/msgdlg.h>
#include <wx/log.h>
enum
{
ID_Hello = 1
};
class MyFrame : public wxFrame
{
public:
MyFrame()
: wxFrame(nullptr, wxID_ANY, "Hello, World!")
{
wxMenu *menuFile = new wxMenu;
menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
"Help string shown in status bar for this menu item");
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!");
this->Bind(wxEVT_MENU,
[](wxCommandEvent& event)
{
wxLogMessage("Hello from wxWidgets!");
}, ID_Hello);
this->Bind(wxEVT_MENU,
[](wxCommandEvent& event)
{
wxMessageBox("This is a wxWidgets' Hello world sample",
"About Hello World", wxOK | wxICON_INFORMATION);
}, wxID_ABOUT);
this->Bind(wxEVT_MENU,
[=](wxCommandEvent& event)
{
this->Close(true);
}, wxID_EXIT);
}
};
class MyApp : public wxApp
{
public:
virtual bool OnInit() override
{
MyFrame* frame = new MyFrame();
frame->Show(true);
return true;
}
};
wxIMPLEMENT_APP(MyApp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment