1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
|
/*
* Copyright (c) 2006 Jan Bracker
*
* main.cpp
*/
// HEADER-INFOMATION ===========================================================
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
// the application icon (under Windows and OS/2 it is in resources)
#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
#include "mondrian.xpm"
#endif
// MAIN APPLICATION ============================================================
class MainApplication : public wxApp
{
public:
virtual bool OnInit();
void OnClickTestButton();
void OnClickBottomButton();
private:
wxFrame *mainFrame;
wxButton *testButton;
wxButton *bottomButton;
wxTextCtrl *textArea;
};
// MAIN FRAMM CLASS ============================================================
class MainFrame : public wxFrame
{
public:
MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
long style = wxDEFAULT_FRAME_STYLE);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
private:
DECLARE_EVENT_TABLE();
};
// MAIN PROGRAMM SOURCE ========================================================
// MainApplication::OnInit() ---------------------------------------------------
bool MainApplication::OnInit()
{
this->mainFrame = new MainFrame(_T("Minimal wxWindows App"), wxPoint(50, 50), wxSize(450, 340));
this->mainFrame->SetBackgroundColour(0x00ff0000);
this->testButton = new wxButton(this->mainFrame, 100, _T("Close"),
wxPoint(20, 20), wxSize(100, 50), wxBU_TOP);
this->testButton->Show(true);
this->bottomButton = new wxButton(this->mainFrame, 101, _T("Hallo"),
wxPoint(120, 20), wxSize(100, 50), wxBU_LEFT);
this->bottomButton->Show(true);
this->textArea = new wxTextCtrl(this->mainFrame, wxID_ANY, wxString("Initial Value of a TextField"), wxPoint(100, 100), wxSize(300, 300));
this->textArea->Show(true);
this->mainFrame->Show(true);
return true;
}
void MainApplication::OnClickTestButton()
{
this->mainFrame->Close(true);
}
void MainApplication::OnClickBottomButton()
{
this->textArea->SetValue(wxString("Test"));
// this->bottomButton->SetLabel(this->textArea->GetValue());
}
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
: wxFrame(NULL, -1, title, pos, size, style)
{
SetIcon(wxICON(mondrian));
}
// MainFrame Event Handlers ----------------------------------------------------
void MainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}
void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxString msg;
msg.Printf( _T("This is the About dialog of the minimal sample.\n")
_T("Welcome to %s"), wxVERSION_STRING);
wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);
}
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// IDs for the controls and the menu commands
enum
{
// menu items
Minimal_Quit = 1,
// it is important for the id corresponding to the "About" command to have
// this standard value as otherwise it won't be handled properly under Mac
// (where it is special and put into the "Apple" menu)
Minimal_About = wxID_ABOUT
};
// ----------------------------------------------------------------------------
// event tables and other macros for wxWindows
// ----------------------------------------------------------------------------
// the event tables connect the wxWindows events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_MENU(Minimal_Quit, MainFrame::OnQuit)
EVT_MENU(Minimal_About, MainFrame::OnAbout)
EVT_BUTTON(100, MainApplication::OnClickTestButton)
EVT_BUTTON(101, MainApplication::OnClickBottomButton)
END_EVENT_TABLE()
// Create a new application object: this macro will allow wxWindows to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also declares the accessor function
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
// not wxApp)
IMPLEMENT_APP(MainApplication) |