简体   繁体   English

wxWidgets EVT_BUTTON函数参数取决于事件来自何处?

[英]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. 我正在使用wxWidgets和EVT_BUTTON makro来管理哪些按钮调用哪些功能。

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. 我有一个ID为1的wxButton

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. 我还有wxWidgets-makro EVT_BUTTON(1,Test::Function) ,当我按下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 我想要的是,我将拥有两个ID为1和2的按钮,这两个按钮都将导致相同的功能,并且在使用该功能时可以区分它们,例如

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 . 使用ID 1ID 2连接Test::Function Inside the event handler compare event.GetId() to ID 1 and ID 2 . 在事件处理程序内部,将event.GetId()ID 1ID 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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