Advertisement
janac

Call Non-Wx Object

Sep 16th, 2021
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <wx/wx.h>
  2.  
  3. class NonWxObject
  4. {
  5. public:
  6.     void say_hello();
  7. };
  8.  
  9. class Button : public wxFrame
  10. {
  11. private:
  12.     NonWxObject thing;
  13. public:
  14.     Button(const wxString& title);
  15.  
  16.     void OnQuit(wxCommandEvent& event);
  17. };
  18.  
  19. /////////////////////////////////////////////
  20.  
  21. #include "button.h"
  22.  
  23. void NonWxObject::say_hello()
  24. {
  25.     wxLogMessage("Hello");
  26. }
  27.  
  28. Button::Button(const wxString& title)
  29.     : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(270, 150))
  30. {
  31.  
  32.     wxPanel* panel = new wxPanel(this, wxID_ANY);
  33.  
  34.     wxButton* button = new wxButton(panel, wxID_EXIT, wxT("Quit"),
  35.         wxPoint(20, 20));
  36.     Connect(wxID_EXIT, wxEVT_COMMAND_BUTTON_CLICKED,
  37.         wxCommandEventHandler(Button::OnQuit));
  38.     button->SetFocus();
  39.     Centre();
  40. }
  41.  
  42.  
  43. void Button::OnQuit(wxCommandEvent& WXUNUSED(event))
  44. {
  45.     thing.say_hello(); //  Close(true);
  46. }
  47.  
  48. //////////////////////////////////////////////////////////////////////////////////
  49.  
  50. #include <wx/wx.h>
  51.  
  52. class MyApp : public wxApp
  53. {
  54. public:
  55.     virtual bool OnInit();
  56. };
  57.  
  58. /////////////////////////////////////////////
  59.  
  60. #include "main.h"
  61. #include "button.h"
  62.  
  63.  
  64.  
  65. IMPLEMENT_APP(MyApp)
  66.  
  67. bool MyApp::OnInit()
  68. {
  69.     Button* btnapp = new Button(wxT("Button"));
  70.     btnapp->Show(true);
  71.  
  72.     return true;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement