]> git.saurik.com Git - wxWidgets.git/blame - samples/minimal/minimal.cpp
regenerated makefiles
[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)
16e8bf31
JS
64 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
65 long style = wxDEFAULT_FRAME_STYLE);
9fdf3c38
VZ
66
67 // event handlers (these functions should _not_ be virtual)
c801d85f
KB
68 void OnQuit(wxCommandEvent& event);
69 void OnAbout(wxCommandEvent& event);
c50f1fb9 70
9fdf3c38
VZ
71private:
72 // any class wishing to process wxWindows events must use this macro
73 DECLARE_EVENT_TABLE()
c801d85f
KB
74};
75
9fdf3c38
VZ
76// ----------------------------------------------------------------------------
77// constants
78// ----------------------------------------------------------------------------
c801d85f 79
9fdf3c38
VZ
80// IDs for the controls and the menu commands
81enum
82{
83 // menu items
1896f99c 84 Minimal_Quit = wxID_EXIT,
9fdf3c38 85
bcbf2881
VZ
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};
82c9f85c 91
9fdf3c38
VZ
92// ----------------------------------------------------------------------------
93// event tables and other macros for wxWindows
94// ----------------------------------------------------------------------------
95
96// the event tables connect the wxWindows 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.
c801d85f 99BEGIN_EVENT_TABLE(MyFrame, wxFrame)
9fdf3c38
VZ
100 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
101 EVT_MENU(Minimal_About, MyFrame::OnAbout)
c801d85f
KB
102END_EVENT_TABLE()
103
9fdf3c38
VZ
104// Create a new application object: this macro will allow wxWindows to create
105// the application object during program execution (it's better than using a
dab73021 106// static object for many reasons) and also implements the accessor function
9fdf3c38
VZ
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// ============================================================================
c801d85f 114
9fdf3c38
VZ
115// ----------------------------------------------------------------------------
116// the application class
117// ----------------------------------------------------------------------------
118
f6bcfd97 119// 'Main program' equivalent: the program execution "starts" here
9fdf3c38
VZ
120bool MyApp::OnInit()
121{
01ca9e8e 122 // create the main application window
bcbf2881 123 MyFrame *frame = new MyFrame(_T("Minimal wxWindows App"),
39d2f9a7 124#ifdef __WXWINCE__
1896f99c 125 wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxSYSTEM_MENU|wxCLIP_CHILDREN);
39d2f9a7
JS
126#else
127 wxPoint(50, 50), wxSize(450, 340));
128#endif
9fdf3c38 129
01ca9e8e
VZ
130 // and show it (the frames, unlike simple controls, are not shown when
131 // created initially)
9fdf3c38 132 frame->Show(TRUE);
9fdf3c38
VZ
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
16e8bf31
JS
145MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
146 : wxFrame(NULL, -1, title, pos, size, style)
c801d85f 147{
9fdf3c38
VZ
148 // set the frame icon
149 SetIcon(wxICON(mondrian));
c801d85f 150
3379ed37 151#if wxUSE_MENUS
d6d26e04 152 // create a menu bar
bcbf2881 153 wxMenu *menuFile = new wxMenu;
c801d85f 154
d6d26e04
RR
155 // the "About" item should be in the help menu
156 wxMenu *helpMenu = new wxMenu;
bcbf2881 157 helpMenu->Append(Minimal_About, _T("&About...\tF1"), _T("Show about dialog"));
c801d85f 158
bcbf2881 159 menuFile->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
01ca9e8e 160
d6d26e04
RR
161 // now append the freshly created menu to the menu bar...
162 wxMenuBar *menuBar = new wxMenuBar();
bcbf2881
VZ
163 menuBar->Append(menuFile, _T("&File"));
164 menuBar->Append(helpMenu, _T("&Help"));
c801d85f 165
9fdf3c38 166 // ... and attach this menu bar to the frame
d6d26e04 167 SetMenuBar(menuBar);
3379ed37 168#endif // wxUSE_MENUS
c801d85f 169
39d2f9a7 170#if wxUSE_STATUSBAR && !defined(__WXWINCE__)
9fdf3c38 171 // create a status bar just for fun (by default with 1 pane only)
47d67540 172 CreateStatusBar(2);
bcbf2881 173 SetStatusText(_T("Welcome to wxWindows!"));
c50f1fb9 174#endif // wxUSE_STATUSBAR
c801d85f
KB
175}
176
c801d85f 177
9fdf3c38
VZ
178// event handlers
179
180void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
c801d85f 181{
9fdf3c38
VZ
182 // TRUE is to force the frame to close
183 Close(TRUE);
c801d85f
KB
184}
185
9fdf3c38 186void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
c801d85f 187{
2f877010 188 wxString msg;
15bee36f 189 msg.Printf( _T("This is the About dialog of the minimal sample.\n")
01ca9e8e 190 _T("Welcome to %s"), wxVERSION_STRING);
2f877010 191
bcbf2881 192 wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);
82c9f85c 193}