Search code examples
c++eventswxwidgets

wxWidgets EVT_BUTTON function parameter depending on where event came from?


I'm using wxWidgets and the EVT_BUTTON makro to manage which buttons call which functions.

What I now want to do is having two different buttons calling the same function with different parameters so that slightly different actions can be executed without duplicating a lot of code.

Of coure another possibility is not call a function with a parameter but to somehow make the separation once the function entered, but I couldn't find any useful information in the event object.

Currently it looks like this:

I have one wxButton with the ID 1.

and I have the function

void Test::Function(wxCommandEvent& event) {
    DoStuff;
}

I also have the wxWidgets-makro EVT_BUTTON(1,Test::Function) which calls the function I have when I press the button wie the ID 1.

What I want is that I'll have two buttons with the IDs 1 and 2 which will both lead to the same function and that I can distinguish them when inside the function, something like

void Test::Function(wxCommandEvent& event) {
    if (event.comesFromtButton1) { //how to realize this is basically my question
        doButton1Stuff;
    } else {
        doButton2Stuff;
    }
}

Solution

  • Connect Test::Function with both ID 1 and ID 2. Inside the event handler compare event.GetId() to ID 1 and ID 2.