Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. // base.h
  2. #ifndef base_h_
  3. #define base_h_
  4.  
  5. class MainApp : public wxApp {
  6. public:
  7. bool OnInit();
  8. };
  9.  
  10. class MainFrame: public wxFrame {
  11. public:
  12. MainFrame( const wxString& title);
  13. wxTextCtrl* firstnumber;
  14. wxTextCtrl* secondnumber;
  15. wxTextCtrl* sum;
  16. void add(wxCommandEvent& event);
  17. };
  18.  
  19. #endif
  20.  
  21. // base.cpp
  22. #include <wx/wxprec.h>
  23. #ifndef WX_PRECOMP
  24. #include <wx/wx.h>
  25. #endif
  26. #include "base.h"
  27.  
  28. IMPLEMENT_APP(MainApp)
  29.  
  30. bool MainApp::OnInit() {
  31. MainFrame *MainWin = new MainFrame(_T("gui"));
  32. MainWin->Show(TRUE);
  33. SetTopWindow(MainWin);
  34. return TRUE;
  35. }
  36.  
  37. MainFrame::MainFrame(const wxString& title): wxFrame((wxFrame*)NULL, -1, title) {
  38. wxPanel* panel = new wxPanel(this);
  39. wxStaticText* firstnumberstatic = new wxStaticText(panel, wxID_ANY, "First number");
  40. firstnumber = new wxTextCtrl(panel,wxID_ANY);
  41. wxStaticText* secondnumberstatic = new wxStaticText(panel, wxID_ANY, "Second number");
  42. secondnumber = new wxTextCtrl(panel,wxID_ANY);
  43. wxButton* add = new wxButton(panel,3,"add");
  44. wxStaticText* sumstatic = new wxStaticText(panel, wxID_ANY, "Sum");
  45. sum = new wxTextCtrl(panel,wxID_ANY);
  46. wxBoxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);
  47. panelSizer->Add(firstnumberstatic, wxSizerFlags().Center());
  48. panelSizer->Add(firstnumber, wxSizerFlags().Center());
  49. panelSizer->Add(secondnumberstatic, wxSizerFlags().Center());
  50. panelSizer->Add(secondnumber, wxSizerFlags().Center());
  51. panelSizer->Add(add, wxSizerFlags().Center());
  52. panelSizer->Add(sumstatic, wxSizerFlags().Center());
  53. panelSizer->Add(sum, wxSizerFlags().Center());
  54. panel->SetSizer(panelSizer);
  55. wxBoxSizer* frameSizer = new wxBoxSizer(wxVERTICAL);
  56. frameSizer->Add(panel, wxSizerFlags().Expand());
  57. SetSizer(frameSizer);
  58. Bind(wxEVT_BUTTON, MainFrame::add, this, 3);
  59. }
  60.  
  61. void MainFrame::add(wxCommandEvent& event) {
  62. sum->SetValue(wxString::Format(_T("%i"),wxAtoi(firstnumber->GetValue())+wxAtoi(secondnumber->GetValue())));
  63. }
  64.  
  65. // base.h
  66. #ifndef base_h_
  67. #define base_h_
  68.  
  69. class MainApp : public wxApp {
  70. public:
  71. bool OnInit();
  72. };
  73.  
  74. class MainFrame: public wxFrame {
  75. public:
  76. MainFrame( const wxString& title);
  77. wxTextCtrl* sum;
  78. wxPanel* panel;
  79. void add(wxCommandEvent& event);
  80. };
  81.  
  82. #endif
  83.  
  84. // base.cpp
  85. #include <wx/wxprec.h>
  86. #ifndef WX_PRECOMP
  87. #include <wx/wx.h>
  88. #endif
  89. #include "base.h"
  90.  
  91. IMPLEMENT_APP(MainApp)
  92.  
  93. bool MainApp::OnInit() {
  94. MainFrame *MainWin = new MainFrame(_T("gui"));
  95. MainWin->Show(TRUE);
  96. SetTopWindow(MainWin);
  97. return TRUE;
  98. }
  99.  
  100. MainFrame::MainFrame(const wxString& title): wxFrame((wxFrame*)NULL, -1, title) {
  101. panel = new wxPanel(this);
  102. wxBoxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);
  103. panelSizer->Add(new wxStaticText(panel, wxID_ANY, "First number"), wxSizerFlags().Center());
  104. panelSizer->Add(new wxTextCtrl(panel, 1), wxSizerFlags().Center());
  105. panelSizer->Add(new wxStaticText(panel, wxID_ANY, "Second number"), wxSizerFlags().Center());
  106. panelSizer->Add(new wxTextCtrl(panel,2), wxSizerFlags().Center());
  107. panelSizer->Add(new wxButton(panel,3,"add"), wxSizerFlags().Center());
  108. panelSizer->Add(new wxStaticText(panel, wxID_ANY, "Sum"), wxSizerFlags().Center());
  109. panelSizer->Add(new wxTextCtrl(panel,4), wxSizerFlags().Center());
  110. panel->SetSizer(panelSizer);
  111. wxBoxSizer* frameSizer = new wxBoxSizer(wxVERTICAL);
  112. frameSizer->Add(panel, wxSizerFlags().Expand());
  113. SetSizer(frameSizer);
  114. Bind(wxEVT_BUTTON, MainFrame::add, this, 3);
  115. }
  116.  
  117. void MainFrame::add(wxCommandEvent& event) {
  118. dynamic_cast<wxTextCtrl*>(panel->FindWindowById(4))->SetValue(wxString::Format(_T("%i"),wxAtoi(dynamic_cast<wxTextCtrl*>(panel->FindWindowById(1))->GetValue())+wxAtoi(dynamic_cast<wxTextCtrl*>(panel->FindWindowById(2))->GetValue())));
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement