How to call an event handler method directly in wxWidgets without an event

孤人 提交于 2019-12-13 04:34:27

问题


Visual Studio 2008 C++ Windows Xp SP3

I have created a wxWidgets form (using wxFormBuilder) and have buttons/menus/toolbars all generating events to call various methods (all this works perfectly). Each of these event methods is defined like this:

void cLoggingFrame::me_InsertCommentText(wxCommandEvent& event);

Now, what I want to be able to do is 're-use' some of these methods by calling them directly. I don't want to generate an event to be handled, I want the method to run when I call it. For example, I want to do something like this (this doesn't work)

me_InsertCommentText(NULL);

Now, I understand that I could have each event method just call another method (without parameters) that could be called from other locations, but in other languages I've been able to bypass the parameter requirement with NULL.

Is there any way to do this with wxWidgets without the need for an additional method?


回答1:


Methods passed to Event-Handlers are just ordinary c++ methods, you have to pass correct parametes something like this will do the trick

me_InsertCommentText(wxCommandEvent());



回答2:


just use the event variable that is already created by wxwidgets. The command line should be like this:

me_InsertCommentText(event);



来源:https://stackoverflow.com/questions/18467103/how-to-call-an-event-handler-method-directly-in-wxwidgets-without-an-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!