]> git.saurik.com Git - wxWidgets.git/blob - samples/minimal/minimal.cpp
Added sashtest GTK makefiles (crashing bug to be solved); added typetest sample
[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 #ifdef __WXGTK__
29 #include "mondrian.xpm"
30 #endif
31
32 // Define a new application type
33 class MyApp: public wxApp
34 { public:
35 bool OnInit(void);
36 };
37
38 // Define a new frame type
39 class MyFrame: public wxFrame
40 { public:
41 MyFrame(wxFrame *parent, const wxString& title,
42 const wxPoint& pos, const wxSize& size);
43
44 public:
45 void OnQuit(wxCommandEvent& event);
46 void OnAbout(wxCommandEvent& event);
47 bool OnClose(void) { return TRUE; }
48
49 DECLARE_EVENT_TABLE()
50
51 };
52
53 // ID for the menu commands
54 #define MINIMAL_QUIT 1
55 #define MINIMAL_TEXT 101
56 #define MINIMAL_ABOUT 102
57
58 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
59 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
60 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
61 END_EVENT_TABLE()
62
63 // Create a new application object
64 IMPLEMENT_APP (MyApp)
65
66 // `Main program' equivalent
67 bool MyApp::OnInit(void)
68 {
69 // Create the main frame window
70 MyFrame *frame = new MyFrame((wxFrame *) NULL, "Minimal wxWindows App",
71 wxPoint(50, 50), wxSize(450, 340));
72
73 // Give it an icon
74 frame->SetIcon(wxICON(mondrian));
75
76 // Make a menubar
77 wxMenu *file_menu = new wxMenu;
78
79 file_menu->Append(MINIMAL_ABOUT, "&About");
80 file_menu->Append(MINIMAL_QUIT, "E&xit");
81 wxMenuBar *menu_bar = new wxMenuBar;
82 menu_bar->Append(file_menu, "&File");
83 frame->SetMenuBar(menu_bar);
84
85 // Make a panel with a message
86 wxPanel *panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL);
87
88 (void)new wxStaticText(panel, 311, "Hello!", wxPoint(10, 10), wxSize(-1, -1), 0);
89
90 // Show the frame
91 frame->Show(TRUE);
92
93 SetTopWindow(frame);
94
95 return TRUE;
96 }
97
98 // My frame constructor
99 MyFrame::MyFrame(wxFrame *parent, const wxString& title,
100 const wxPoint& pos, const wxSize& size):
101 wxFrame(parent, -1, title, pos, size)
102 {}
103
104 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
105 {
106 Close(TRUE);
107 }
108
109 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
110 {
111 wxMessageDialog dialog(this, "This is a minimal sample\nA second line in the message box",
112 "About Minimal", wxYES_NO|wxCANCEL);
113
114 dialog.ShowModal();
115 }
116
117