2021年4月30日星期五

How to open specific windows to specific buttons on wxWidgets?

I did my research before coming here and couldn't find anything helpful. Please bare with me as I'm a newbie in wxWidgets and C++ GUI. I created a 3x3 grid, each button with its own purpose. When clicked, some should open a new page containing at least what the button text says, and other buttons should direct you to the website that's on the button. I tried creating a new window within the event handlers but nothing shows up even if I use Show(); I have a cApp, class which is the launcher for the application and cMain that is the graphical interface implementation. I will show cMain only.

cMAIN.H

#pragma once  //Graphical interface component  #include "wx/wx.h"    class cMain : public wxFrame  {  public:      cMain();      ~cMain();  public:      int nFieldWidth = 3;      int nFieldHeight = 3;      wxButton** btn;            void OnButtonClicked0(wxCommandEvent& evt);      void OnButtonClicked1(wxCommandEvent &evt);      void OnButtonClicked2(wxCommandEvent &evt);      void OnButtonClicked3(wxCommandEvent &evt);      void OnButtonClicked4(wxCommandEvent &evt);      void OnButtonClicked5(wxCommandEvent &evt);      void OnButtonClicked6(wxCommandEvent &evt);      void OnButtonClicked7(wxCommandEvent &evt);      void OnButtonClicked8(wxCommandEvent &evt);      wxDECLARE_EVENT_TABLE();  };  

cMAIN.CPP

#include "cMain.h"  #include "cApp.h"  #include <string>  wxBEGIN_EVENT_TABLE(cMain, wxFrame)  EVT_BUTTON(0, OnButtonClicked0)  EVT_BUTTON(1, OnButtonClicked1)  EVT_BUTTON(2, OnButtonClicked2)  EVT_BUTTON(3, OnButtonClicked3)  EVT_BUTTON(4, OnButtonClicked4)  EVT_BUTTON(5, OnButtonClicked5)  EVT_BUTTON(6, OnButtonClicked6)  EVT_BUTTON(7, OnButtonClicked7)  EVT_BUTTON(8, OnButtonClicked8)  wxEND_EVENT_TABLE();      cMain::cMain() : wxFrame(nullptr, wxID_ANY, "3x3Grid", wxPoint(30,30), wxSize(800,600))//overriding the frame  {      btn = new wxButton * [nFieldWidth * nFieldHeight]; // creating an array of buttons of size nFW * nFH      wxGridSizer* grid = new wxGridSizer(nFieldWidth, nFieldHeight, 10, 10); //creating new sizer grid        wxFont font(24, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false);        for (int x = 0; x < nFieldWidth; x++)      {          for (int y = 0; y < nFieldHeight; y++)          {              btn[y * nFieldWidth + x] = new wxButton(this, 10000 + (y * nFieldWidth + x), std::to_string(y * nFieldWidth + x)); //sets button[index] = a new button              btn[y * nFieldWidth + x]->SetFont(font); //set font              grid->Add(btn[y * nFieldWidth + x], 1, wxEXPAND | wxALL); //adds button to grid          }      }      btn[0]->SetLabel("Input Data");      btn[1]->SetLabel("Read Data from File");      btn[2]->SetLabel("Open www.website.com");      btn[3]->SetLabel("Lookup Data");      btn[4]->SetLabel("Open website.com");      btn[5]->SetLabel("Open https://website.com");      btn[6]->SetLabel("Store Data to File");      btn[7]->SetLabel("Open https://website.com");      btn[8]->SetLabel("Help");        this->SetSizer(grid);      grid->Layout();        }      cMain::~cMain()  {      delete[]btn;  }    void cMain::OnButtonClicked0(wxCommandEvent& evt)  {      cMain* inputwindow = new cMain();      inputwindow->Show();  }    void cMain::OnButtonClicked1(wxCommandEvent& evt)  {  }  void cMain::OnButtonClicked2(wxCommandEvent& evt)  {  }  void cMain::OnButtonClicked3(wxCommandEvent& evt)  {  }  void cMain::OnButtonClicked4(wxCommandEvent& evt)  {  }  void cMain::OnButtonClicked5(wxCommandEvent& evt)  {  }  void cMain::OnButtonClicked6(wxCommandEvent& evt)  {  }  void cMain::OnButtonClicked7(wxCommandEvent& evt)  {  }  void cMain::OnButtonClicked8(wxCommandEvent& evt)  {  }  
https://stackoverflow.com/questions/67340584/how-to-open-specific-windows-to-specific-buttons-on-wxwidgets May 01, 2021 at 05:20AM

没有评论:

发表评论