]>
git.saurik.com Git - wxWidgets.git/blob - samples/minimal/minimal.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Minimal wxWindows sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "minimal.cpp"
22 #pragma interface "minimal.cpp"
25 // For compilers that support precompilation, includes "wx/wx.h".
26 #include "wx/wxprec.h"
32 // for all others, include the necessary headers (this file is usually all you
33 // need because it includes almost all "standard" wxWindows headers)
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
41 // the application icon
42 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
43 #include "mondrian.xpm"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // Define a new application type, each program should derive a class from wxApp
51 class MyApp
: public wxApp
54 // override base class virtuals
55 // ----------------------------
57 // this one is called on application startup and is a good place for the app
58 // initialization (doing it here and not in the ctor allows to have an error
59 // return: if OnInit() returns false, the application terminates)
60 virtual bool OnInit();
63 // Define a new frame type: this is going to be our main frame
64 class MyFrame
: public wxFrame
68 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
70 // event handlers (these functions should _not_ be virtual)
71 void OnQuit(wxCommandEvent
& event
);
72 void OnAbout(wxCommandEvent
& event
);
75 // any class wishing to process wxWindows events must use this macro
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 // IDs for the controls and the menu commands
91 // ----------------------------------------------------------------------------
92 // event tables and other macros for wxWindows
93 // ----------------------------------------------------------------------------
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.
98 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
99 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
100 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
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
105 // static object for many reasons) and also declares the accessor function
106 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
110 #ifdef __WXUNIVERSAL__
111 #include "wx/univ/theme.h"
115 #endif // __WXUNIVERSAL__
117 // ============================================================================
119 // ============================================================================
121 // ----------------------------------------------------------------------------
122 // the application class
123 // ----------------------------------------------------------------------------
125 // 'Main program' equivalent: the program execution "starts" here
128 // create the main application window
129 MyFrame
*frame
= new MyFrame("Minimal wxWindows App",
130 wxPoint(50, 50), wxSize(450, 340));
132 // and show it (the frames, unlike simple controls, are not shown when
133 // created initially)
136 // success: wxApp::OnRun() will be called which will enter the main message
137 // loop and the application will run. If we returned FALSE here, the
138 // application would exit immediately.
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
147 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
148 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
151 // we need this in order to allow the about menu relocation, since ABOUT is
152 // not the default id of the about menu
153 wxApp::s_macAboutMenuItemId
= Minimal_About
;
156 // set the frame icon
157 SetIcon(wxICON(mondrian
));
160 wxMenu
*menuFile
= new wxMenu("", wxMENU_TEAROFF
);
162 // the "About" item should be in the help menu
163 wxMenu
*helpMenu
= new wxMenu
;
164 helpMenu
->Append(Minimal_About
, "&About...\tCtrl-A", "Show about dialog");
166 menuFile
->Append(Minimal_Quit
, "E&xit\tAlt-X", "Quit this program");
168 // now append the freshly created menu to the menu bar...
169 wxMenuBar
*menuBar
= new wxMenuBar();
170 menuBar
->Append(menuFile
, "&File");
171 menuBar
->Append(helpMenu
, "&Help");
173 // ... and attach this menu bar to the frame
177 // create a status bar just for fun (by default with 1 pane only)
179 SetStatusText("Welcome to wxWindows!");
180 #endif // wxUSE_STATUSBAR
186 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
188 // TRUE is to force the frame to close
192 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
195 msg
.Printf( _T("This is the about dialog of minimal sample.\n")
196 _T("Welcome to %s"), wxVERSION_STRING
);
198 wxMessageBox(msg
, "About Minimal", wxOK
| wxICON_INFORMATION
, this);