]> git.saurik.com Git - wxWidgets.git/blame - samples/minimal/minimal.cpp
Update OpenVMS compile support
[wxWidgets.git] / samples / minimal / minimal.cpp
CommitLineData
e5a2506d
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: minimal.cpp
3// Purpose: Minimal wxWidgets sample
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
1dbcdf2d 11
e5a2506d
RR
12// ============================================================================
13// declarations
14// ============================================================================
1dbcdf2d 15
e5a2506d
RR
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
ce00f59b 19
e5a2506d
RR
20// For compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
ce00f59b 22
e5a2506d
RR
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27// for all others, include the necessary headers (this file is usually all you
28// need because it includes almost all "standard" wxWidgets headers)
29#ifndef WX_PRECOMP
30 #include "wx/wx.h"
31#endif
32
33// ----------------------------------------------------------------------------
34// resources
35// ----------------------------------------------------------------------------
36
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)
e7092398 39#ifndef wxHAS_IMAGES_IN_RESOURCES
e5a2506d
RR
40 #include "../sample.xpm"
41#endif
42
43// ----------------------------------------------------------------------------
44// private classes
45// ----------------------------------------------------------------------------
46
47// Define a new application type, each program should derive a class from wxApp
48class MyApp : public wxApp
1dbcdf2d
VZ
49{
50public:
e5a2506d
RR
51 // override base class virtuals
52 // ----------------------------
53
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();
1dbcdf2d
VZ
58};
59
e5a2506d
RR
60// Define a new frame type: this is going to be our main frame
61class MyFrame : public wxFrame
62{
63public:
64 // ctor(s)
65 MyFrame(const wxString& title);
66
67 // event handlers (these functions should _not_ be virtual)
68 void OnQuit(wxCommandEvent& event);
69 void OnAbout(wxCommandEvent& event);
70
71private:
72 // any class wishing to process wxWidgets events must use this macro
73 DECLARE_EVENT_TABLE()
74};
75
76// ----------------------------------------------------------------------------
77// constants
78// ----------------------------------------------------------------------------
79
80// IDs for the controls and the menu commands
81enum
82{
83 // menu items
84 Minimal_Quit = wxID_EXIT,
85
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
90};
91
92// ----------------------------------------------------------------------------
93// event tables and other macros for wxWidgets
94// ----------------------------------------------------------------------------
95
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.
99BEGIN_EVENT_TABLE(MyFrame, wxFrame)
100 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
101 EVT_MENU(Minimal_About, MyFrame::OnAbout)
102END_EVENT_TABLE()
103
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
108// not wxApp)
109IMPLEMENT_APP(MyApp)
110
111// ============================================================================
112// implementation
113// ============================================================================
114
115// ----------------------------------------------------------------------------
116// the application class
117// ----------------------------------------------------------------------------
118
119// 'Main program' equivalent: the program execution "starts" here
120bool MyApp::OnInit()
121{
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() )
125 return false;
126
127 // create the main application window
f906a23e 128 MyFrame *frame = new MyFrame("Minimal wxWidgets App");
e5a2506d
RR
129
130 // and show it (the frames, unlike simple controls, are not shown when
131 // created initially)
132 frame->Show(true);
133
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.
137 return true;
138}
139
140// ----------------------------------------------------------------------------
141// main frame
142// ----------------------------------------------------------------------------
143
144// frame constructor
145MyFrame::MyFrame(const wxString& title)
146 : wxFrame(NULL, wxID_ANY, title)
147{
148 // set the frame icon
149 SetIcon(wxICON(sample));
150
151#if wxUSE_MENUS
152 // create a menu bar
153 wxMenu *fileMenu = new wxMenu;
154
155 // the "About" item should be in the help menu
156 wxMenu *helpMenu = new wxMenu;
2d143b66 157 helpMenu->Append(Minimal_About, "&About\tF1", "Show about dialog");
e5a2506d 158
f906a23e 159 fileMenu->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");
e5a2506d
RR
160
161 // now append the freshly created menu to the menu bar...
162 wxMenuBar *menuBar = new wxMenuBar();
f906a23e
VZ
163 menuBar->Append(fileMenu, "&File");
164 menuBar->Append(helpMenu, "&Help");
e5a2506d
RR
165
166 // ... and attach this menu bar to the frame
167 SetMenuBar(menuBar);
168#endif // wxUSE_MENUS
169
170#if wxUSE_STATUSBAR
171 // create a status bar just for fun (by default with 1 pane only)
172 CreateStatusBar(2);
f906a23e 173 SetStatusText("Welcome to wxWidgets!");
e5a2506d
RR
174#endif // wxUSE_STATUSBAR
175}
176
177
178// event handlers
179
180void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
181{
182 // true is to force the frame to close
183 Close(true);
184}
185
186void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
187{
f906a23e
VZ
188 wxMessageBox(wxString::Format
189 (
190 "Welcome to %s!\n"
191 "\n"
192 "This is the minimal wxWidgets sample\n"
193 "running under %s.",
e5a2506d 194 wxVERSION_STRING,
f906a23e 195 wxGetOsDescription()
e5a2506d 196 ),
f906a23e 197 "About wxWidgets minimal sample",
e5a2506d
RR
198 wxOK | wxICON_INFORMATION,
199 this);
200}