Ticket #40931: hw_wx.cpp

File hw_wx.cpp, 1.0 KB (added by jxy (Xiao-Yong), 10 years ago)

hello-world using wxFrame

Line 
1#include <wx/wx.h>
2
3class MyApp : public wxApp
4{
5  virtual bool OnInit();
6};
7
8IMPLEMENT_APP(MyApp)
9
10class MyFrame : public wxFrame
11{
12public:
13  MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
14  void OnQuit(wxCommandEvent& event);
15};
16
17enum
18  {
19    ID_Quit=1
20  };
21
22
23bool MyApp::OnInit()
24{
25  MyFrame *frame = new MyFrame( _("Hello World"), wxPoint(50, 50),
26                                wxSize(450, 350));
27
28  frame->Connect( ID_Quit, wxEVT_COMMAND_MENU_SELECTED,
29                  (wxObjectEventFunction) &MyFrame::OnQuit );
30
31  frame->Show(true);
32  SetTopWindow(frame);
33  return true;
34}
35
36MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
37  : wxFrame( NULL, -1, title, pos, size )
38{
39  wxMenuBar *menuBar = new wxMenuBar;
40  wxMenu *menuFile = new wxMenu;
41
42  menuFile->Append( ID_Quit, _("E&xit") );
43  menuBar->Append(menuFile, _("&File") );
44  SetMenuBar(menuBar);
45
46  CreateStatusBar();
47  SetStatusText( _("Welcome to wxWidgets!") );
48}
49
50void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
51{
52  Close(true);
53}