]> git.saurik.com Git - wxWidgets.git/blame - samples/minimal/minimal.cpp
Applied patch #845888 (Fixes compilation of regtest sample in Unicode/ANSI, debug...
[wxWidgets.git] / samples / minimal / minimal.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: minimal.cpp
3// Purpose: Minimal wxWindows sample
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
e2a6f233
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
9fdf3c38
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
0731c594 19
c801d85f
KB
20// For compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
9fdf3c38 24 #pragma hdrstop
c801d85f
KB
25#endif
26
9fdf3c38 27// for all others, include the necessary headers (this file is usually all you
f6bcfd97 28// need because it includes almost all "standard" wxWindows headers)
c801d85f 29#ifndef WX_PRECOMP
9fdf3c38 30 #include "wx/wx.h"
c801d85f
KB
31#endif
32
9fdf3c38 33// ----------------------------------------------------------------------------
f6bcfd97 34// resources
9fdf3c38 35// ----------------------------------------------------------------------------
bcbf2881
VZ
36
37// the application icon (under Windows and OS/2 it is in resources)
ea596687 38#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
9fdf3c38 39 #include "mondrian.xpm"
d355d3fe
RR
40#endif
41
9fdf3c38
VZ
42// ----------------------------------------------------------------------------
43// private classes
44// ----------------------------------------------------------------------------
45
46// Define a new application type, each program should derive a class from wxApp
47class MyApp : public wxApp
48{
49public:
50 // override base class virtuals
51 // ----------------------------
52
53 // this one is called on application startup and is a good place for the app
54 // initialization (doing it here and not in the ctor allows to have an error
55 // return: if OnInit() returns false, the application terminates)
56 virtual bool OnInit();
c801d85f
KB
57};
58
9fdf3c38
VZ
59// Define a new frame type: this is going to be our main frame
60class MyFrame : public wxFrame
61{
62public:
63 // ctor(s)
0bff3f69 64 MyFrame(const wxString& title);
9fdf3c38
VZ
65
66 // event handlers (these functions should _not_ be virtual)
c801d85f
KB
67 void OnQuit(wxCommandEvent& event);
68 void OnAbout(wxCommandEvent& event);
c50f1fb9 69
9fdf3c38
VZ
70private:
71 // any class wishing to process wxWindows events must use this macro
72 DECLARE_EVENT_TABLE()
c801d85f
KB
73};
74
9fdf3c38
VZ
75// ----------------------------------------------------------------------------
76// constants
77// ----------------------------------------------------------------------------
c801d85f 78
9fdf3c38
VZ
79// IDs for the controls and the menu commands
80enum
81{
82 // menu items
1896f99c 83 Minimal_Quit = wxID_EXIT,
9fdf3c38 84
bcbf2881
VZ
85 // it is important for the id corresponding to the "About" command to have
86 // this standard value as otherwise it won't be handled properly under Mac
87 // (where it is special and put into the "Apple" menu)
88 Minimal_About = wxID_ABOUT
89};
82c9f85c 90
9fdf3c38
VZ
91// ----------------------------------------------------------------------------
92// event tables and other macros for wxWindows
93// ----------------------------------------------------------------------------
94
95// the event tables connect the wxWindows events with the functions (event
96// handlers) which process them. It can be also done at run-time, but for the
97// simple menu events like this the static method is much simpler.
c801d85f 98BEGIN_EVENT_TABLE(MyFrame, wxFrame)
9fdf3c38
VZ
99 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
100 EVT_MENU(Minimal_About, MyFrame::OnAbout)
c801d85f
KB
101END_EVENT_TABLE()
102
9fdf3c38
VZ
103// Create a new application object: this macro will allow wxWindows to create
104// the application object during program execution (it's better than using a
dab73021 105// static object for many reasons) and also implements the accessor function
9fdf3c38
VZ
106// wxGetApp() which will return the reference of the right type (i.e. MyApp and
107// not wxApp)
108IMPLEMENT_APP(MyApp)
109
110// ============================================================================
111// implementation
112// ============================================================================
c801d85f 113
9fdf3c38
VZ
114// ----------------------------------------------------------------------------
115// the application class
116// ----------------------------------------------------------------------------
117
f6bcfd97 118// 'Main program' equivalent: the program execution "starts" here
9fdf3c38
VZ
119bool MyApp::OnInit()
120{
01ca9e8e 121 // create the main application window
0bff3f69 122 MyFrame *frame = new MyFrame(_T("Minimal wxWindows App"));
9fdf3c38 123
01ca9e8e
VZ
124 // and show it (the frames, unlike simple controls, are not shown when
125 // created initially)
9fdf3c38 126 frame->Show(TRUE);
9fdf3c38
VZ
127
128 // success: wxApp::OnRun() will be called which will enter the main message
129 // loop and the application will run. If we returned FALSE here, the
130 // application would exit immediately.
131 return TRUE;
132}
133
134// ----------------------------------------------------------------------------
135// main frame
136// ----------------------------------------------------------------------------
137
138// frame constructor
0bff3f69
VZ
139MyFrame::MyFrame(const wxString& title)
140 : wxFrame(NULL, -1, title)
c801d85f 141{
9fdf3c38
VZ
142 // set the frame icon
143 SetIcon(wxICON(mondrian));
c801d85f 144
3379ed37 145#if wxUSE_MENUS
d6d26e04 146 // create a menu bar
bcbf2881 147 wxMenu *menuFile = new wxMenu;
c801d85f 148
d6d26e04
RR
149 // the "About" item should be in the help menu
150 wxMenu *helpMenu = new wxMenu;
bcbf2881 151 helpMenu->Append(Minimal_About, _T("&About...\tF1"), _T("Show about dialog"));
c801d85f 152
bcbf2881 153 menuFile->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
01ca9e8e 154
d6d26e04
RR
155 // now append the freshly created menu to the menu bar...
156 wxMenuBar *menuBar = new wxMenuBar();
bcbf2881
VZ
157 menuBar->Append(menuFile, _T("&File"));
158 menuBar->Append(helpMenu, _T("&Help"));
c801d85f 159
9fdf3c38 160 // ... and attach this menu bar to the frame
d6d26e04 161 SetMenuBar(menuBar);
3379ed37 162#endif // wxUSE_MENUS
c801d85f 163
39d2f9a7 164#if wxUSE_STATUSBAR && !defined(__WXWINCE__)
9fdf3c38 165 // create a status bar just for fun (by default with 1 pane only)
47d67540 166 CreateStatusBar(2);
bcbf2881 167 SetStatusText(_T("Welcome to wxWindows!"));
c50f1fb9 168#endif // wxUSE_STATUSBAR
c801d85f
KB
169}
170
c801d85f 171
9fdf3c38
VZ
172// event handlers
173
174void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
c801d85f 175{
9fdf3c38
VZ
176 // TRUE is to force the frame to close
177 Close(TRUE);
c801d85f
KB
178}
179
9fdf3c38 180void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
c801d85f 181{
2f877010 182 wxString msg;
15bee36f 183 msg.Printf( _T("This is the About dialog of the minimal sample.\n")
01ca9e8e 184 _T("Welcome to %s"), wxVERSION_STRING);
2f877010 185
bcbf2881 186 wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);
82c9f85c 187}