Question

I'm making my first steps in learning wxWidgets. I learnt how to assign events to Menu Items or Buttons for example, because they do have IDs. 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. 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.

Any help here? I'd like that method to be executed just when a specific Menu is clicked, but not all! Thanks in beforehand.

Was it helpful?

Solution

Assuming you want MainFrame::Config to be called if the menu item created by

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top