1 Index
: samples
/minimal
/minimal
.cpp
2 ===================================================================
3 RCS file
: /pack
/cvsroots
/wxwidgets
/wxWidgets
/samples
/minimal
/minimal
.cpp
,v
4 retrieving revision
1.71
5 diff
-B
-b
-u
-2 -p
-r1
.71 minimal
.cpp
6 --- samples
/minimal
/minimal
.cpp
2006/06/29 13:47:45 1.71
7 +++ samples
/minimal
/minimal
.cpp
2006/11/04 20:50:29
9 -/////////////////////////////////////////////////////////////////////////////
11 -// Purpose: Minimal wxWidgets sample
12 -// Author: Julian Smart
16 -// Copyright: (c) Julian Smart
17 -// Licence: wxWindows licence
18 -/////////////////////////////////////////////////////////////////////////////
20 -// ============================================================================
22 -// ============================================================================
24 -// ----------------------------------------------------------------------------
26 -// ----------------------------------------------------------------------------
28 -// For compilers that support precompilation, includes "wx/wx.h".
29 -#include "wx/wxprec.h"
35 -// for all others, include the necessary headers (this file is usually all you
36 -// need because it includes almost all "standard" wxWidgets headers)
41 -// ----------------------------------------------------------------------------
43 -// ----------------------------------------------------------------------------
45 -// the application icon (under Windows and OS/2 it is in resources and even
46 -// though we could still include the XPM here it would be unused)
47 -#if !defined(__WXMSW__) && !defined(__WXPM__)
48 - #include "../sample.xpm"
51 -// ----------------------------------------------------------------------------
53 -// ----------------------------------------------------------------------------
55 -// Define a new application type, each program should derive a class from wxApp
56 -class MyApp
: public wxApp
59 - // override base class virtuals
60 - // ----------------------------
62 - // this one is called on application startup and is a good place for the app
63 - // initialization (doing it here and not in the ctor allows to have an error
64 - // return: if OnInit() returns false, the application terminates)
65 - virtual bool OnInit();
68 -// Define a new frame type: this is going to be our main frame
69 -class MyFrame
: public wxFrame
73 - MyFrame(const wxString
& title
);
75 - // event handlers (these functions should _not_ be virtual)
76 - void OnQuit(wxCommandEvent
& event
);
77 - void OnAbout(wxCommandEvent
& event
);
80 - // any class wishing to process wxWidgets events must use this macro
81 - DECLARE_EVENT_TABLE()
84 -// ----------------------------------------------------------------------------
86 -// ----------------------------------------------------------------------------
88 -// IDs for the controls and the menu commands
92 - Minimal_Quit
= wxID_EXIT
,
94 - // it is important for the id corresponding to the "About" command to have
95 - // this standard value as otherwise it won't be handled properly under Mac
96 - // (where it is special and put into the "Apple" menu)
97 - Minimal_About
= wxID_ABOUT
100 -// ----------------------------------------------------------------------------
101 -// event tables and other macros for wxWidgets
102 -// ----------------------------------------------------------------------------
104 -// the event tables connect the wxWidgets events with the functions (event
105 -// handlers) which process them. It can be also done at run-time, but for the
106 -// simple menu events like this the static method is much simpler.
107 -BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
108 - EVT_MENU(Minimal_Quit
, MyFrame
::OnQuit
)
109 - EVT_MENU(Minimal_About
, MyFrame
::OnAbout
)
112 -// Create a new application object: this macro will allow wxWidgets to create
113 -// the application object during program execution (it's better than using a
114 -// static object for many reasons) and also implements the accessor function
115 -// wxGetApp() which will return the reference of the right type (i.e. MyApp and
117 -IMPLEMENT_APP(MyApp
)
119 -// ============================================================================
121 -// ============================================================================
123 -// ----------------------------------------------------------------------------
124 -// the application class
125 -// ----------------------------------------------------------------------------
127 -// 'Main program' equivalent: the program execution "starts" here
128 -bool MyApp
::OnInit()
130 - // call the base class initialization method, currently it only parses a
131 - // few common command-line options but it could be do more in the future
132 - if ( !wxApp
::OnInit() )
135 - // create the main application window
136 - MyFrame
*frame
= new MyFrame(_T("Minimal wxWidgets App"));
138 - // and show it (the frames, unlike simple controls, are not shown when
139 - // created initially)
142 - // success: wxApp::OnRun() will be called which will enter the main message
143 - // loop and the application will run. If we returned false here, the
144 - // application would exit immediately.
148 -// ----------------------------------------------------------------------------
150 -// ----------------------------------------------------------------------------
152 -// frame constructor
153 -MyFrame
::MyFrame(const wxString
& title
)
154 - : wxFrame(NULL
, wxID_ANY
, title
)
156 - // set the frame icon
157 - SetIcon(wxICON(sample
));
160 - // create a menu bar
161 - wxMenu
*fileMenu
= new wxMenu
;
163 - // the "About" item should be in the help menu
164 - wxMenu
*helpMenu
= new wxMenu
;
165 - helpMenu
->Append(Minimal_About
, _T("&About...\tF1"), _T("Show about dialog"));
167 - fileMenu
->Append(Minimal_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
169 - // now append the freshly created menu to the menu bar...
170 - wxMenuBar
*menuBar
= new wxMenuBar();
171 - menuBar
->Append(fileMenu
, _T("&File"));
172 - menuBar
->Append(helpMenu
, _T("&Help"));
174 - // ... and attach this menu bar to the frame
175 - SetMenuBar(menuBar
);
176 -#endif // wxUSE_MENUS
179 - // create a status bar just for fun (by default with 1 pane only)
180 - CreateStatusBar(2);
181 - SetStatusText(_T("Welcome to wxWidgets!"));
182 -#endif // wxUSE_STATUSBAR
188 -void MyFrame
::OnQuit(wxCommandEvent
& WXUNUSED(event
))
190 - // true is to force the frame to close
194 -void MyFrame
::OnAbout(wxCommandEvent
& WXUNUSED(event
))
196 - wxMessageBox(wxString
::Format(
197 - _T("Welcome to %s!\n")
199 - _T("This is the minimal wxWidgets sample\n")
200 - _T("running under %s."),
202 - wxGetOsDescription().c_str()
204 - _T("About wxWidgets minimal sample"),
205 - wxOK
| wxICON_INFORMATION
,