From WxWiki
Jump to navigation Jump to search
Official Classes SmallBlocks.png Archive Containers Controls Data Structures Database Date & Time Debug Device Contexts Dialogs Document & Views Drag & Drop Events Filesystem Frames Graphics Grid Cell Help HTML Logging Miscellaneous Networking Printing Sizers Streams Threading Windows

A menu bar is a series of menus accessible from the top of a frame and not actual controls, although they appear as though they are, they are really just child classes of the frame they are attached to, this is due to variations in how different platforms handle menu bars.

Remarks: To respond to a menu selection, provide a handler for EVT_MENU, in the frame that contains the menu bar.

If you have a toolbar which uses the same identifiers as your EVT_MENU entries, events from the toolbar will also be processed by your EVT_MENU event handlers.

Tip: under Windows, if you discover that menu shortcuts (for example, Alt-F to show the file menu) are not working, check any EVT_CHAR events you are handling in child windows. If you are not calling event.Skip() for events that you don't process in these event handlers, menu shortcuts may cease to work.


Here is my code for my custom toolbar class...

    // ***** View Menu
    viewMenu = new wxMenu();
    managementMenuItem = new wxMenuItem(viewMenu, wxID_ANY, _("Management"), _("Toggle the management area"), wxITEM_NORMAL);
    editingMenuItem = new wxMenuItem(viewMenu, wxID_ANY, _("Editing"), _("Toggle the editing area"), wxITEM_NORMAL);
    outputMenuItem = new wxMenuItem(viewMenu, wxID_ANY, _("Output"), _("Toggle the output area"), wxITEM_NORMAL);

    toolbarsMenu = new wxMenu();
    customizeMenuItem = new wxMenuItem(toolbarsMenu, wxID_ANY, _("Customize"), _("Customize the toolbars"), wxITEM_NORMAL);
    editMenuItem = new wxMenuItem(toolbarsMenu, wxID_ANY, _("Edit"), _("Customize the toolbars"), wxITEM_NORMAL);
    viewMenu->AppendSubMenu(toolbarsMenu, _("&Toolbars"));

Custom wxMenuBar class

To propagate events to a custom menu bar class, do this...

    frame->Connect(quitMenuItem->GetId(),wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(MainMenubar::OnQuit), NULL, this);

Without the last two parameters the event function will be called on the frame, even though it is a member of the custom menu bar class.

See Also