]> git.saurik.com Git - wxWidgets.git/blame - samples/minimal/minimal.cpp
Attempting to check in this wretched cursor again. Also added SetAcceleratorTable
[wxWidgets.git] / samples / minimal / minimal.cpp
CommitLineData
c801d85f
KB
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
d355d3fe
RR
28#ifdef __WXGTK__
29#include "mondrian.xpm"
30#endif
31
c801d85f
KB
32// Define a new application type
33class MyApp: public wxApp
34{ public:
35 bool OnInit(void);
36};
37
38// Define a new frame type
39class 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 DECLARE_EVENT_TABLE()
49
50};
51
52// ID for the menu commands
53#define MINIMAL_QUIT 1
54#define MINIMAL_TEXT 101
55#define MINIMAL_ABOUT 102
56
57BEGIN_EVENT_TABLE(MyFrame, wxFrame)
58 EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
59 EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
60END_EVENT_TABLE()
61
62// Create a new application object
63IMPLEMENT_APP (MyApp)
64
65// `Main program' equivalent, creating windows and returning main app frame
66bool MyApp::OnInit(void)
67{
68 // Create the main frame window
69 MyFrame *frame = new MyFrame(NULL, "Minimal wxWindows App", 50, 50, 450, 340);
70
71 // Give it an icon
2049ba38 72#ifdef __WXMSW__
c801d85f
KB
73 frame->SetIcon(wxIcon("mondrian"));
74#endif
d355d3fe
RR
75#ifdef __WXGTK__
76 frame->SetIcon(wxIcon( mondrian_xpm ));
c801d85f
KB
77#endif
78
79 // Make a menubar
80 wxMenu *file_menu = new wxMenu;
81
82 file_menu->Append(MINIMAL_ABOUT, "&About");
83 file_menu->Append(MINIMAL_QUIT, "E&xit");
84 wxMenuBar *menu_bar = new wxMenuBar;
85 menu_bar->Append(file_menu, "&File");
86 frame->SetMenuBar(menu_bar);
87
88 // Make a panel with a message
89 wxPanel *panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL);
90
e3e65dac 91 (void)new wxStaticText(panel, 311, "Hello!", wxPoint(10, 10), wxSize(-1, -1), 0);
c801d85f
KB
92
93 // Show the frame
94 frame->Show(TRUE);
95
96 SetTopWindow(frame);
97
98 return TRUE;
99}
100
101// My frame constructor
102MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
103 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
104{}
105
bd7d06f2 106void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
107{
108 Close(TRUE);
109}
110
bd7d06f2 111void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
112{
113 wxMessageDialog dialog(this, "This is a minimal sample\nA second line in the message box",
114 "About Minimal", wxYES_NO|wxCANCEL);
115
116 dialog.ShowModal();
117}
118
119