]>
git.saurik.com Git - wxWidgets.git/blob - build/bakefiles/wxpresets/sample/minimal.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Minimal wxWindows sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWindows headers)
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 // Define a new application type, each program should derive a class from wxApp
43 class MyApp
: public wxApp
46 // override base class virtuals
47 // ----------------------------
49 // this one is called on application startup and is a good place for the app
50 // initialization (doing it here and not in the ctor allows to have an error
51 // return: if OnInit() returns false, the application terminates)
52 virtual bool OnInit();
55 // Define a new frame type: this is going to be our main frame
56 class MyFrame
: public wxFrame
60 MyFrame(const wxString
& title
);
62 // event handlers (these functions should _not_ be virtual)
63 void OnQuit(wxCommandEvent
& event
);
64 void OnAbout(wxCommandEvent
& event
);
67 // any class wishing to process wxWindows events must use this macro
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 // IDs for the controls and the menu commands
79 Minimal_Quit
= wxID_EXIT
,
81 // it is important for the id corresponding to the "About" command to have
82 // this standard value as otherwise it won't be handled properly under Mac
83 // (where it is special and put into the "Apple" menu)
84 Minimal_About
= wxID_ABOUT
87 // ----------------------------------------------------------------------------
88 // event tables and other macros for wxWindows
89 // ----------------------------------------------------------------------------
91 // the event tables connect the wxWindows events with the functions (event
92 // handlers) which process them. It can be also done at run-time, but for the
93 // simple menu events like this the static method is much simpler.
94 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
95 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
96 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
99 // Create a new application object: this macro will allow wxWindows to create
100 // the application object during program execution (it's better than using a
101 // static object for many reasons) and also implements the accessor function
102 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
106 // ============================================================================
108 // ============================================================================
110 // ----------------------------------------------------------------------------
111 // the application class
112 // ----------------------------------------------------------------------------
114 // 'Main program' equivalent: the program execution "starts" here
117 // create the main application window
118 MyFrame
*frame
= new MyFrame(wxT("Minimal wxWindows App"));
120 // and show it (the frames, unlike simple controls, are not shown when
121 // created initially)
124 // success: wxApp::OnRun() will be called which will enter the main message
125 // loop and the application will run. If we returned false here, the
126 // application would exit immediately.
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
135 MyFrame::MyFrame(const wxString
& title
)
136 : wxFrame(NULL
, wxID_ANY
, title
)
138 // set the frame icon
142 wxMenu
*menuFile
= new wxMenu
;
144 // the "About" item should be in the help menu
145 wxMenu
*helpMenu
= new wxMenu
;
146 helpMenu
->Append(Minimal_About
, wxT("&About\tF1"), wxT("Show about dialog"));
148 menuFile
->Append(Minimal_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
150 // now append the freshly created menu to the menu bar...
151 wxMenuBar
*menuBar
= new wxMenuBar();
152 menuBar
->Append(menuFile
, wxT("&File"));
153 menuBar
->Append(helpMenu
, wxT("&Help"));
155 // ... and attach this menu bar to the frame
157 #endif // wxUSE_MENUS
160 // create a status bar just for fun (by default with 1 pane only)
162 SetStatusText(wxT("Welcome to wxWindows!"));
163 #endif // wxUSE_STATUSBAR
169 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
171 // true is to force the frame to close
175 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
178 msg
.Printf( wxT("This is the About dialog of the minimal sample.\n")
179 wxT("Welcome to %s"), wxVERSION_STRING
);
181 wxMessageBox(msg
, wxT("About Minimal"), wxOK
| wxICON_INFORMATION
, this);