-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainform.cpp
225 lines (174 loc) · 6.76 KB
/
mainform.cpp
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/////////////////////////////////////////////////////////////////////////////
// Name: mainform.cpp
// Purpose:
// Author: Sergey Talipov
// Modified by:
// Created: 14/11/2023 13:41:03
// RCS-ID:
// Copyright: 15681627-3C745D8E-630127F2
// Licence:
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
////@begin includes
////@end includes
#include "mainform.h"
////@begin XPM images
#include "tsnsoft.xpm"
#include "wxwidgets.xpm"
////@end XPM images
/*
* MainForm type definition
*/
IMPLEMENT_CLASS( MainForm, wxFrame )
/*
* MainForm event table definition
*/
BEGIN_EVENT_TABLE( MainForm, wxFrame )
////@begin MainForm event table entries
EVT_BUTTON( ID_BUTTON, MainForm::OnButtonClick )
////@end MainForm event table entries
END_EVENT_TABLE()
/*
* MainForm constructors
*/
MainForm::MainForm()
{
Init();
}
MainForm::MainForm( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
Init();
Create( parent, id, caption, pos, size, style );
}
/*
* MainForm creator
*/
bool MainForm::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin MainForm creation
wxFrame::Create( parent, id, caption, pos, size, style );
CreateControls();
SetIcon(GetIconResource(wxT("tsnsoft.xpm")));
if (GetSizer())
{
GetSizer()->SetSizeHints(this);
}
Centre();
////@end MainForm creation
return true;
}
/*
* MainForm destructor
*/
MainForm::~MainForm()
{
////@begin MainForm destruction
////@end MainForm destruction
}
/*
* Member initialisation
*/
void MainForm::Init()
{
////@begin MainForm member initialisation
////@end MainForm member initialisation
}
/*
* Control creation for MainForm
*/
void MainForm::CreateControls()
{
////@begin MainForm content construction
MainForm* itemFrame1 = this;
wxGridBagSizer* itemGridBagSizer1 = new wxGridBagSizer(0, 0);
itemGridBagSizer1->SetEmptyCellSize(wxSize(10, 19));
itemFrame1->SetSizer(itemGridBagSizer1);
wxStaticText* itemStaticText1 = new wxStaticText( itemFrame1, wxID_STATIC, wxT("Введите а:"), wxDefaultPosition, wxDefaultSize, 0 );
itemGridBagSizer1->Add(itemStaticText1, wxGBPosition(1, 2), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 4);
wxTextCtrl* itemTextCtrl1 = new wxTextCtrl( itemFrame1, ID_TEXTCTRL_a, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
itemGridBagSizer1->Add(itemTextCtrl1, wxGBPosition(1, 6), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 4);
wxStaticText* itemStaticText2 = new wxStaticText( itemFrame1, wxID_STATIC, wxT("Введите b:"), wxDefaultPosition, wxDefaultSize, 0 );
itemGridBagSizer1->Add(itemStaticText2, wxGBPosition(3, 2), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 4);
wxButton* itemButton3 = new wxButton( itemFrame1, ID_BUTTON, wxT("Поделить"), wxDefaultPosition, wxDefaultSize, 0 );
itemGridBagSizer1->Add(itemButton3, wxGBPosition(5, 6), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 4);
wxStaticText* itemStaticText4 = new wxStaticText( itemFrame1, wxID_STATIC_Result, wxT("Результат"), wxDefaultPosition, wxDefaultSize, 0 );
itemGridBagSizer1->Add(itemStaticText4, wxGBPosition(7, 2), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 4);
wxTextCtrl* itemTextCtrl2 = new wxTextCtrl( itemFrame1, ID_TEXTCTRL_b, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
itemGridBagSizer1->Add(itemTextCtrl2, wxGBPosition(3, 6), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 4);
wxTextCtrl* itemTextCtrl3 = new wxTextCtrl( itemFrame1, ID_TEXTCTRL_c, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
itemGridBagSizer1->Add(itemTextCtrl3, wxGBPosition(7, 6), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 4);
wxStaticBitmap* itemStaticBitmap1 = new wxStaticBitmap( itemFrame1, wxID_STATIC, itemFrame1->GetBitmapResource(wxT("wxwidgets.xpm")), wxDefaultPosition, wxSize(60, 46), 0 );
itemGridBagSizer1->Add(itemStaticBitmap1, wxGBPosition(5, 2), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
////@end MainForm content construction
}
/*
* Should we show tooltips?
*/
bool MainForm::ShowToolTips()
{
return true;
}
/*
* Get bitmap resources
*/
wxBitmap MainForm::GetBitmapResource( const wxString& name )
{
// Bitmap retrieval
////@begin MainForm bitmap retrieval
wxUnusedVar(name);
if (name == wxT("wxwidgets.xpm"))
{
wxBitmap bitmap(wxwidgets_xpm);
return bitmap;
}
return wxNullBitmap;
////@end MainForm bitmap retrieval
}
/*
* Get icon resources
*/
wxIcon MainForm::GetIconResource( const wxString& name )
{
// Icon retrieval
////@begin MainForm icon retrieval
wxUnusedVar(name);
if (name == wxT("tsnsoft.xpm"))
{
wxIcon icon(tsnsoft_xpm);
return icon;
}
return wxNullIcon;
////@end MainForm icon retrieval
}
/*
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
*/
// Рассчитать
void MainForm::OnButtonClick(wxCommandEvent& event)
{
double a, b; // входные данные
wxTextCtrl* itemTextCtrl1 = (wxTextCtrl*)FindWindow(ID_TEXTCTRL_a); // находим компонент a по ID
wxTextCtrl* itemTextCtrl2 = (wxTextCtrl*)FindWindow(ID_TEXTCTRL_b); // находим компонент b по ID
wxTextCtrl* itemTextCtrl3 = (wxTextCtrl*)FindWindow(ID_TEXTCTRL_c); // находим компонент c по ID
if (!itemTextCtrl1->GetValue().ToDouble(&a)) { // получаем значение из компонента a
wxMessageBox(wxT("a не число!")); // выводим сообщение об ошибке
return; // выходим из функции
}
if (!itemTextCtrl2->GetValue().ToDouble(&b)) { // получаем значение из компонента b
wxMessageBox(wxT("b не число!")); // выводим сообщение об ошибке
return; // выходим из функции
}
double c = a / b; // вычисляем результат
if (isnan(c) || isinf(c)) { // проверяем результат на ошибки
wxMessageBox(wxT("результат не число!")); // выводим сообщение об ошибке
return; // выходим из функции
}
itemTextCtrl3->SetValue(wxString::Format(wxT("%0.3f"), c)); // выводим результат в компонент c
}