简体   繁体   中英

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;
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM