Binding event to wxMenu instead of wxMenuItem

喜夏-厌秋 提交于 2019-12-24 18:17:39

问题


Im creating a dynamic MenuBar from xml file, and binding events to menu items using Connect().
Some menus does not have items inside, but needs to fire events.
Is there a way to attach an event handler to a wxMenu using Connect()?

*Im Using wxWidgets 2.8.8 & MS VC++ 6.0


回答1:


Ive tried many things, but nothing worked out for me.
As a quick answaer ill quote Vadim Zeitlin from wx-widgets list:

No, you shouldn't associate commands directly to top level menus. This is discouraged under all systems and is not supported at all under some of them.




回答2:


I think you can trap EVT_MENU_OPEN (see wxMenuEvent).

Connecting it might look like this:

Connect(wxEVT_MENU_OPEN, wxMenuEventHandler(MyFrame::OnMenuOpen), 0, 0);


来源:https://stackoverflow.com/questions/2174584/binding-event-to-wxmenu-instead-of-wxmenuitem

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