Advertisement
Guest User

wxWidgets problem

a guest
Feb 22nd, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.05 KB | None | 0 0
  1. /***************************************************************
  2.  * Name:      GUIMain.cpp
  3.  * Purpose:   Code for Application Frame
  4.  * Author:    Krystian Duczek ()
  5.  * Created:   2020-02-21
  6.  * Copyright: Krystian Duczek ()
  7.  * License:
  8.  **************************************************************/
  9.  
  10. #include "wx_pch.h"
  11. #include "GUIMain.h"
  12. #include <wx/msgdlg.h>
  13. #include "C:\Users\User\Desktop\Shel\Console\Shelter.h" //----need to give direct path because otherwise compiler cant see this
  14. #include "C:\Users\User\Desktop\Shel\Console\Shelter.cpp" //----this is weird but without this compiler cant refer to constructor or destructor
  15.  
  16. //(*InternalHeaders(GUIFrame)
  17. #include <wx/bitmap.h>
  18. #include <wx/image.h>
  19. #include <wx/intl.h>
  20. #include <wx/string.h>
  21. //*)
  22.  
  23. //helper functions
  24. enum wxbuildinfoformat {
  25.     short_f, long_f };
  26.  
  27. wxString wxbuildinfo(wxbuildinfoformat format)
  28. {
  29.     wxString wxbuild(wxVERSION_STRING);
  30.  
  31.     if (format == long_f )
  32.     {
  33. #if defined(__WXMSW__)
  34.         wxbuild << _T("-Windows");
  35. #elif defined(__UNIX__)
  36.         wxbuild << _T("-Linux");
  37. #endif
  38.  
  39. #if wxUSE_UNICODE
  40.         wxbuild << _T("-Unicode build");
  41. #else
  42.         wxbuild << _T("-ANSI build");
  43. #endif // wxUSE_UNICODE
  44.     }
  45.  
  46.     return wxbuild;
  47. }
  48.  
  49. //(*IdInit(GUIFrame)
  50. const long GUIFrame::ID_STATICBITMAP1 = wxNewId();
  51. const long GUIFrame::ID_BUTTON1 = wxNewId();
  52. const long GUIFrame::ID_BUTTON2 = wxNewId();
  53. const long GUIFrame::ID_BUTTON3 = wxNewId();
  54. const long GUIFrame::ID_LISTBOX1 = wxNewId();
  55. const long GUIFrame::ID_BUTTON4 = wxNewId();
  56. const long GUIFrame::ID_BUTTON5 = wxNewId();
  57. const long GUIFrame::ID_BUTTON6 = wxNewId();
  58. const long GUIFrame::ID_BUTTON7 = wxNewId();
  59. const long GUIFrame::ID_PANEL1 = wxNewId();
  60. const long GUIFrame::idMenuQuit = wxNewId();
  61. const long GUIFrame::idMenuAbout = wxNewId();
  62. const long GUIFrame::ID_STATUSBAR1 = wxNewId();
  63. //*)
  64.  
  65. BEGIN_EVENT_TABLE(GUIFrame,wxFrame)
  66.     //(*EventTable(GUIFrame)
  67.     //*)
  68. END_EVENT_TABLE()
  69.  
  70. GUIFrame::GUIFrame(wxWindow* parent,wxWindowID id)
  71. {
  72.     //(*Initialize(GUIFrame)
  73.     wxBoxSizer* BoxSizer1;
  74.     wxFlexGridSizer* FlexGridSizer1;
  75.     wxMenu* Menu1;
  76.     wxMenu* Menu2;
  77.     wxMenuBar* MenuBar1;
  78.     wxMenuItem* MenuItem1;
  79.     wxMenuItem* MenuItem2;
  80.  
  81.     Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
  82.     BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
  83.     Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
  84.     FlexGridSizer1 = new wxFlexGridSizer(0, 3, 0, 0);
  85.     FlexGridSizer1->Add(106,57,1, wxALL|wxEXPAND, 5);
  86.     StaticBitmap1 = new wxStaticBitmap(Panel1, ID_STATICBITMAP1, wxBitmap(wxImage(_T("C:\\Users\\User\\Desktop\\Shel\\GUI\\Logo.PNG"))), wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER, _T("ID_STATICBITMAP1"));
  87.     FlexGridSizer1->Add(StaticBitmap1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  88.     FlexGridSizer1->Add(0,0,1, wxALL|wxEXPAND, 5);
  89.     Button1 = new wxButton(Panel1, ID_BUTTON1, _("See Status"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
  90.     FlexGridSizer1->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  91.     Button2 = new wxButton(Panel1, ID_BUTTON2, _("Select Healthy Animals"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
  92.     FlexGridSizer1->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  93.     Button3 = new wxButton(Panel1, ID_BUTTON3, _("Add an Animal"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
  94.     FlexGridSizer1->Add(Button3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  95.     ListBox1 = new wxListBox(Panel1, ID_LISTBOX1, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX1"));
  96.     FlexGridSizer1->Add(ListBox1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  97.     FlexGridSizer1->Add(0,0,1, wxALL|wxEXPAND, 5);
  98.     Button4 = new wxButton(Panel1, ID_BUTTON4, _("Adopt an Animal"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
  99.     FlexGridSizer1->Add(Button4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  100.     Button5 = new wxButton(Panel1, ID_BUTTON5, _("Export Status to CSV"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON5"));
  101.     FlexGridSizer1->Add(Button5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  102.     Button6 = new wxButton(Panel1, ID_BUTTON6, _("Export Status to TXT"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON6"));
  103.     FlexGridSizer1->Add(Button6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  104.     Button7 = new wxButton(Panel1, ID_BUTTON7, _("Quit"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON7"));
  105.     FlexGridSizer1->Add(Button7, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  106.     Panel1->SetSizer(FlexGridSizer1);
  107.     FlexGridSizer1->Fit(Panel1);
  108.     FlexGridSizer1->SetSizeHints(Panel1);
  109.     BoxSizer1->Add(Panel1, 1, wxALL|wxEXPAND, 0);
  110.     SetSizer(BoxSizer1);
  111.     MenuBar1 = new wxMenuBar();
  112.     Menu1 = new wxMenu();
  113.     MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
  114.     Menu1->Append(MenuItem1);
  115.     MenuBar1->Append(Menu1, _("&File"));
  116.     Menu2 = new wxMenu();
  117.     MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
  118.     Menu2->Append(MenuItem2);
  119.     MenuBar1->Append(Menu2, _("Help"));
  120.     SetMenuBar(MenuBar1);
  121.     StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
  122.     int __wxStatusBarWidths_1[1] = { -1 };
  123.     int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
  124.     StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
  125.     StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
  126.     SetStatusBar(StatusBar1);
  127.     BoxSizer1->Fit(this);
  128.     BoxSizer1->SetSizeHints(this);
  129.  
  130.     Connect(ID_BUTTON7,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&GUIFrame::OnButton7Click);
  131.     Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&GUIFrame::OnQuit);
  132.     Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&GUIFrame::OnAbout);
  133.     //*)
  134.     Shelter Sunshine;
  135.     MYSQL* conn;
  136.  
  137.     conn = mysql_init(0); //allocation object for connection
  138.     conn = mysql_real_connect(conn, "192.168.1.7", "donq104", "admin", "shelter", 0, NULL, 0);
  139. }
  140. //-----So i want to create a Shelter instance for example in a constructor and have access to this instance in OnButton7Click
  141.  
  142. GUIFrame::~GUIFrame()
  143. {
  144.     //(*Destroy(GUIFrame)
  145.     //*)
  146. }
  147. bool GUIFrame::OnInit(wxCommandEvent& event)
  148. {
  149.     return true;
  150. }
  151.  
  152. void GUIFrame::OnQuit(wxCommandEvent& event)
  153. {
  154.     Close();
  155. }
  156.  
  157. void GUIFrame::OnAbout(wxCommandEvent& event)
  158. {
  159.     wxString msg = wxbuildinfo(long_f);
  160.     wxMessageBox(msg, _("Welcome to..."));
  161. }
  162.  
  163. void GUIFrame::OnButton7Click(wxCommandEvent& event)
  164. {
  165.     Sunshine.close(conn, Sunshine); //-----here is the problem
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement