]>
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 // ----------------------------------------------------------------------------
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" wxWindows headers)
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 // the application icon (under Windows and OS/2 it is in resources)
38 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
39 #include "mondrian.xpm"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 // Define a new application type, each program should derive a class from wxApp
47 class MyApp
: public wxApp
50 // override base class virtuals
51 // ----------------------------
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();
59 // Define a new frame type: this is going to be our main frame
60 class MyFrame
: public wxFrame
64 MyFrame(const wxString
& title
);
66 // event handlers (these functions should _not_ be virtual)
67 void OnQuit(wxCommandEvent
& event
);
68 void OnAbout(wxCommandEvent
& event
);
71 // any class wishing to process wxWindows events must use this macro
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 // IDs for the controls and the menu commands
83 Minimal_Quit
= wxID_EXIT
,
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
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 implements the accessor function
106 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
110 // ============================================================================
112 // ============================================================================
114 // ----------------------------------------------------------------------------
115 // the application class
116 // ----------------------------------------------------------------------------
118 // 'Main program' equivalent: the program execution "starts" here
121 // create the main application window
122 MyFrame
*frame
= new MyFrame(_T("Minimal wxWindows App"));
124 // and show it (the frames, unlike simple controls, are not shown when
125 // created initially)
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.
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
139 MyFrame::MyFrame(const wxString
& title
)
140 : wxFrame(NULL
, wxID_ANY
, title
)
142 // set the frame icon
143 SetIcon(wxICON(mondrian
));
147 wxMenu
*menuFile
= new wxMenu
;
149 // the "About" item should be in the help menu
150 wxMenu
*helpMenu
= new wxMenu
;
151 helpMenu
->Append(Minimal_About
, _T("&About...\tF1"), _T("Show about dialog"));
153 menuFile
->Append(Minimal_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
155 // now append the freshly created menu to the menu bar...
156 wxMenuBar
*menuBar
= new wxMenuBar();
157 menuBar
->Append(menuFile
, _T("&File"));
158 menuBar
->Append(helpMenu
, _T("&Help"));
160 // ... and attach this menu bar to the frame
162 #endif // wxUSE_MENUS
164 #if wxUSE_STATUSBAR && !defined(__WXWINCE__)
165 // create a status bar just for fun (by default with 1 pane only)
167 SetStatusText(_T("Welcome to wxWindows!"));
168 #endif // wxUSE_STATUSBAR
174 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
176 // true is to force the frame to close
180 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
183 msg
.Printf( _T("This is the About dialog of the minimal sample.\n")
184 _T("Welcome to %s"), wxVERSION_STRING
);
186 wxMessageBox(msg
, _T("About Minimal"), wxOK
| wxICON_INFORMATION
, this);