]>
git.saurik.com Git - wxWidgets.git/blob - samples/minimal/minimal.cpp
9ca10c1580ee502a89afbdcf426726c408554678
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Minimal wxWidgets 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" wxWidgets headers)
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 // the application icon (under Windows and OS/2 it is in resources and even
38 // though we could still include the XPM here it would be unused)
39 #if !defined(__WXMSW__) && !defined(__WXPM__)
40 #include "../sample.xpm"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 // Define a new application type, each program should derive a class from wxApp
48 class MyApp
: public wxApp
51 // override base class virtuals
52 // ----------------------------
54 // this one is called on application startup and is a good place for the app
55 // initialization (doing it here and not in the ctor allows to have an error
56 // return: if OnInit() returns false, the application terminates)
57 virtual bool OnInit();
60 // Define a new frame type: this is going to be our main frame
61 class MyFrame
: public wxFrame
65 MyFrame(const wxString
& title
);
67 // event handlers (these functions should _not_ be virtual)
68 void OnQuit(wxCommandEvent
& event
);
69 void OnAbout(wxCommandEvent
& event
);
72 // any class wishing to process wxWidgets events must use this macro
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 // IDs for the controls and the menu commands
84 Minimal_Quit
= wxID_EXIT
,
86 // it is important for the id corresponding to the "About" command to have
87 // this standard value as otherwise it won't be handled properly under Mac
88 // (where it is special and put into the "Apple" menu)
89 Minimal_About
= wxID_ABOUT
92 // ----------------------------------------------------------------------------
93 // event tables and other macros for wxWidgets
94 // ----------------------------------------------------------------------------
96 // the event tables connect the wxWidgets events with the functions (event
97 // handlers) which process them. It can be also done at run-time, but for the
98 // simple menu events like this the static method is much simpler.
99 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
100 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
101 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
104 // Create a new application object: this macro will allow wxWidgets to create
105 // the application object during program execution (it's better than using a
106 // static object for many reasons) and also implements the accessor function
107 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
111 // ============================================================================
113 // ============================================================================
115 // ----------------------------------------------------------------------------
116 // the application class
117 // ----------------------------------------------------------------------------
119 // 'Main program' equivalent: the program execution "starts" here
122 // call the base class initialization method, currently it only parses a
123 // few common command-line options but it could be do more in the future
124 if ( !wxApp::OnInit() )
127 // create the main application window
128 MyFrame
*frame
= new MyFrame(_T("Minimal wxWidgets App"));
130 // and show it (the frames, unlike simple controls, are not shown when
131 // created initially)
134 // success: wxApp::OnRun() will be called which will enter the main message
135 // loop and the application will run. If we returned false here, the
136 // application would exit immediately.
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
145 MyFrame::MyFrame(const wxString
& title
)
146 : wxFrame(NULL
, wxID_ANY
, title
)
148 // set the frame icon
149 SetIcon(wxICON(sample
));
153 wxMenu
*fileMenu
= new wxMenu
;
155 // the "About" item should be in the help menu
156 wxMenu
*helpMenu
= new wxMenu
;
157 helpMenu
->Append(Minimal_About
, _T("&About...\tF1"), _T("Show about dialog"));
159 fileMenu
->Append(Minimal_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
161 // now append the freshly created menu to the menu bar...
162 wxMenuBar
*menuBar
= new wxMenuBar();
163 menuBar
->Append(fileMenu
, _T("&File"));
164 menuBar
->Append(helpMenu
, _T("&Help"));
166 // ... and attach this menu bar to the frame
168 #endif // wxUSE_MENUS
171 // create a status bar just for fun (by default with 1 pane only)
173 SetStatusText(_T("Welcome to wxWidgets!"));
174 #endif // wxUSE_STATUSBAR
176 wxTextCtrl
* text
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
| wxTE_DONTWRAP
);
177 text
->SetValue( wxT("0 /////////////////////////////////////////////////////////////////////////////\n\
178 1 // Name: minimal.cpp\n\
179 2 // Purpose: Minimal wxWidgets sample\n\
180 3 // Author: Julian Smart\n\
182 5 // Created: 04/01/98\n\
184 7 // Copyright: (c) Julian Smart\n\
185 8 // Licence: wxWindows licence\n\
186 9 /////////////////////////////////////////////////////////////////////////////\n\
189 text
->WriteText( wxT("10 /////////////////////////////////////////////////////////////////////////////\n\
190 11 // Name: minimal.cpp\n\
191 12 // Purpose: Minimal wxWidgets sample\n\
192 13 // Author: Julian Smart\n\
193 14 // Modified by:\n\
194 15 // Created: 04/01/98\n\
195 16 // RCS-ID: $Id$\n\
196 17 // Copyright: (c) Julian Smart\n\
197 18 // Licence: wxWindows licence\n\
198 19 /////////////////////////////////////////////////////////////////////////////") );
204 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
206 // true is to force the frame to close
210 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
212 wxMessageBox(wxString::Format(
213 _T("Welcome to %s!\n")
215 _T("This is the minimal wxWidgets sample\n")
216 _T("running under %s."),
218 wxGetOsDescription().c_str()
220 _T("About wxWidgets minimal sample"),
221 wxOK
| wxICON_INFORMATION
,