简体   繁体   English

将单个事件连接到wxWidgets中的特定方法

[英]Connecting a single event to a specific method in wxWidgets

I'm making my first steps in learning wxWidgets. 我正在学习wxWidgets的第一步。 I learnt how to assign events to Menu Items or Buttons for example, because they do have IDs. 我学习了如何将事件分配给菜单项或按钮,例如,因为它们确实具有ID。 But when I tried to assign an event to a Menu, I found it real difficult. 但是,当我尝试将事件分配给菜单时,我发现这确实很困难。

My aim was to asign one of those top Menus from the MenuBar a specific event, rather than them having a list of Menu Items. 我的目的是为MenuBar中的那些顶级菜单分配一个特定的事件,而不是让它们具有Menu Items列表。 At first I didn't manage it, until I thought on using: 最初,我没有管理它,直到我考虑使用:

Connect(wxEVT_MENU_OPEN, wxCommandEventHandler(MainFrame::Config));

This worked fine, until I realized this now happens to all Menus! 一切正常,直到我意识到所有菜单现在都发生这种情况! Which is evident though, as there is no place where I specified the Connect command to apply only for that Menu. 但是,这很明显,因为在任何地方我都没有指定Connect命令适用于该菜单。

Any help here? 这里有什么帮助吗? I'd like that method to be executed just when a specific Menu is clicked, but not all! 我希望在单击特定菜单时才执行该方法,但不是全部! Thanks in beforehand. 在此先感谢。

Assuming you want MainFrame::Config to be called if the menu item created by 假设如果菜单项由创建,则要调用MainFrame :: Config

yourMenu->Append(SOME_ID, wxT("&Configuration"));

gets clicked, use 被点击,使用

this->Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::Config, this, SOME_ID);

if this is your mainframe. 如果是您的大型机。

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

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