]> git.saurik.com Git - wxWidgets.git/blob - samples/dynamic/minimal.cpp
demo of wxYield() bug
[wxWidgets.git] / samples / dynamic / minimal.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: minimal.cpp
3 // Purpose: Dynamic events 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 *frame, char *title, int x, int y, int w, int h);
42
43 public:
44 void OnQuit(wxCommandEvent& event);
45 void OnAbout(wxCommandEvent& event);
46 bool OnClose(void) { return TRUE; }
47 };
48
49 // ID for the menu commands
50 #define MINIMAL_QUIT 1
51 #define MINIMAL_TEXT 101
52 #define MINIMAL_ABOUT 102
53
54 // Create a new application object
55 IMPLEMENT_APP (MyApp)
56
57 // `Main program' equivalent, creating windows and returning main app frame
58 bool MyApp::OnInit(void)
59 {
60 // Create the main frame window
61 MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "Minimal wxWindows App", 50, 50, 450, 340);
62
63 frame->Connect( MINIMAL_QUIT, -1, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)MyFrame::OnQuit );
64 frame->Connect( MINIMAL_ABOUT, -1, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)MyFrame::OnAbout );
65
66 // Give it an icon
67 #ifdef __WXMSW__
68 frame->SetIcon(wxIcon("mondrian"));
69 #else
70 frame->SetIcon(wxIcon(mondrian_xpm));
71 #endif
72
73 // Make a menubar
74 wxMenu *file_menu = new wxMenu;
75
76 file_menu->Append(MINIMAL_ABOUT, "&About");
77 file_menu->Append(MINIMAL_QUIT, "E&xit");
78 wxMenuBar *menu_bar = new wxMenuBar;
79 menu_bar->Append(file_menu, "&File");
80 frame->SetMenuBar(menu_bar);
81
82 // Make a panel with a message
83 wxPanel *panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL);
84
85 (void)new wxStaticText(panel, 311, "Hello!", wxPoint(10, 10), wxSize(-1, -1), 0);
86
87 // Show the frame
88 frame->Show(TRUE);
89
90 SetTopWindow(frame);
91
92 return TRUE;
93 }
94
95 // My frame constructor
96 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
97 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
98 {}
99
100 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
101 {
102 Close(TRUE);
103 }
104
105 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
106 {
107 wxMessageDialog dialog(this, "This is a minimal sample\nA second line in the message box",
108 "About Minimal", wxYES_NO|wxCANCEL);
109
110 dialog.ShowModal();
111 }
112
113