warning msgs
[wxWidgets.git] / samples / minimal / minimal.cpp
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$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "minimal.cpp"
14 #pragma interface "minimal.cpp"
15 #endif
16
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WX_PRECOMP
25 #include "wx/wx.h"
26 #endif
27
28 // Define a new application type
29 class MyApp: public wxApp
30 { public:
31 bool OnInit(void);
32 };
33
34 // Define a new frame type
35 class MyFrame: public wxFrame
36 { public:
37 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
38
39 public:
40 void OnQuit(wxCommandEvent& event);
41 void OnAbout(wxCommandEvent& event);
42 bool OnClose(void) { return TRUE; }
43
44 DECLARE_EVENT_TABLE()
45
46 };
47
48 // ID for the menu commands
49 #define MINIMAL_QUIT 1
50 #define MINIMAL_TEXT 101
51 #define MINIMAL_ABOUT 102
52
53 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
54 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
55 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
56 END_EVENT_TABLE()
57
58 // Create a new application object
59 IMPLEMENT_APP (MyApp)
60
61 // `Main program' equivalent, creating windows and returning main app frame
62 bool MyApp::OnInit(void)
63 {
64 // Create the main frame window
65 MyFrame *frame = new MyFrame(NULL, "Minimal wxWindows App", 50, 50, 450, 340);
66
67 // Give it an icon
68 #ifdef __WXMSW__
69 frame->SetIcon(wxIcon("mondrian"));
70 #endif
71 #ifdef __X__
72 frame->SetIcon(wxIcon("aiai.xbm"));
73 #endif
74
75 // Make a menubar
76 wxMenu *file_menu = new wxMenu;
77
78 file_menu->Append(MINIMAL_ABOUT, "&About");
79 file_menu->Append(MINIMAL_QUIT, "E&xit");
80 wxMenuBar *menu_bar = new wxMenuBar;
81 menu_bar->Append(file_menu, "&File");
82 frame->SetMenuBar(menu_bar);
83
84 // Make a panel with a message
85 wxPanel *panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL);
86
87 (void)new wxStaticText(panel, 311, "Hello!", wxPoint(10, 10), wxSize(-1, -1), 0);
88
89 // Show the frame
90 frame->Show(TRUE);
91
92 SetTopWindow(frame);
93
94 return TRUE;
95 }
96
97 // My frame constructor
98 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
99 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
100 {}
101
102 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
103 {
104 Close(TRUE);
105 }
106
107 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
108 {
109 wxMessageDialog dialog(this, "This is a minimal sample\nA second line in the message box",
110 "About Minimal", wxYES_NO|wxCANCEL);
111
112 dialog.ShowModal();
113 }
114
115