I'm trying to set up a window in WXWidgets with a grid of buttons. Each of these buttons will open another window. Now I know I can do this by having the call to each window in a separate function depending on the button that was pressed. But that seems a bit inefficient.
What I want to do is have each of these buttons call the same function when clicked, but pass an ID which will be used to determine which window is opened up.
The basic code I'm using is as follow (bits are stripped out, I have a button that closes the application, just to test buttons out)
Simple::Simple(const wxString& title, int x, int y)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(x,y))
{
wxPanel *testPanel = new wxPanel(this,wxID_ANY, wxDefaultPosition,wxSize(270, 150));
wxButton *testButton = new wxButton(testPanel, wxID_EXIT, wxT("Actors"), wxPoint(20,20));
Connect(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(Simple::eventWindowCall));
testButton->SetFocus();
Centre();
}
void Simple::eventWindowCall(wxCommandEvent & WXUNUSED(event))
{
Close(true); //just a line to make sure this function is being called
}
I've already tried using a number in place of an event ID when using connect, but the button's function doesn't get called if I do that. Ideally, I could just do something like wxCommandEventHandler(Simple::eventWindowCall(26)) and put a case statement in the eventWindowCall function that would show the correct window based on the number pased. But so far, that aproach has also been inefective.
Any advice you can offer would be great. Thanks for reading this. I've been working on figuring this out for hours.