]>
git.saurik.com Git - wxWidgets.git/blob - distrib/autopackage/sample/minimal.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Minimal wxWindows sample
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
26 // for all others, include the necessary headers (this file is usually all you
27 // need because it includes almost all "standard" wxWindows headers)
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // Define a new application type, each program should derive a class from wxApp
42 class MyApp
: public wxApp
45 // override base class virtuals
46 // ----------------------------
48 // this one is called on application startup and is a good place for the app
49 // initialization (doing it here and not in the ctor allows to have an error
50 // return: if OnInit() returns false, the application terminates)
51 virtual bool OnInit();
54 // Define a new frame type: this is going to be our main frame
55 class MyFrame
: public wxFrame
59 MyFrame(const wxString
& title
);
61 // event handlers (these functions should _not_ be virtual)
62 void OnQuit(wxCommandEvent
& event
);
63 void OnAbout(wxCommandEvent
& event
);
66 // any class wishing to process wxWindows events must use this macro
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 // IDs for the controls and the menu commands
78 Minimal_Quit
= wxID_EXIT
,
80 // it is important for the id corresponding to the "About" command to have
81 // this standard value as otherwise it won't be handled properly under Mac
82 // (where it is special and put into the "Apple" menu)
83 Minimal_About
= wxID_ABOUT
86 // ----------------------------------------------------------------------------
87 // event tables and other macros for wxWindows
88 // ----------------------------------------------------------------------------
90 // the event tables connect the wxWindows events with the functions (event
91 // handlers) which process them. It can be also done at run-time, but for the
92 // simple menu events like this the static method is much simpler.
93 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
94 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
95 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
98 // Create a new application object: this macro will allow wxWindows to create
99 // the application object during program execution (it's better than using a
100 // static object for many reasons) and also implements the accessor function
101 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
105 // ============================================================================
107 // ============================================================================
109 // ----------------------------------------------------------------------------
110 // the application class
111 // ----------------------------------------------------------------------------
113 // 'Main program' equivalent: the program execution "starts" here
116 // create the main application window
117 MyFrame
*frame
= new MyFrame(wxT("Minimal wxWindows App"));
119 // and show it (the frames, unlike simple controls, are not shown when
120 // created initially)
123 // success: wxApp::OnRun() will be called which will enter the main message
124 // loop and the application will run. If we returned false here, the
125 // application would exit immediately.
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
134 MyFrame::MyFrame(const wxString
& title
)
135 : wxFrame(NULL
, wxID_ANY
, title
)
137 // set the frame icon
141 wxMenu
*menuFile
= new wxMenu
;
143 // the "About" item should be in the help menu
144 wxMenu
*helpMenu
= new wxMenu
;
145 helpMenu
->Append(Minimal_About
, wxT("&About\tF1"), wxT("Show about dialog"));
147 menuFile
->Append(Minimal_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
149 // now append the freshly created menu to the menu bar...
150 wxMenuBar
*menuBar
= new wxMenuBar();
151 menuBar
->Append(menuFile
, wxT("&File"));
152 menuBar
->Append(helpMenu
, wxT("&Help"));
154 // ... and attach this menu bar to the frame
156 #endif // wxUSE_MENUS
159 // create a status bar just for fun (by default with 1 pane only)
161 SetStatusText(wxT("Welcome to wxWindows!"));
162 #endif // wxUSE_STATUSBAR
168 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
170 // true is to force the frame to close
174 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
177 msg
.Printf( wxT("This is the About dialog of the minimal sample.\n")
178 wxT("Welcome to %s"), wxVERSION_STRING
);
180 wxMessageBox(msg
, wxT("About Minimal"), wxOK
| wxICON_INFORMATION
, this);