## wxMenuBar

A menu bar is a series of menus accessible from the top of a frame.

Derived from

wxEvtHandler
wxObject

Include files

<wx/menu.h>

Event handling

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.

Note that menu commands (and UI update events for menus) are first sent to the focus window within the frame. If no window within the frame has the focus, then the events are sent directly to the frame. This allows command and UI update handling to be processed by specific windows and controls, and not necessarily by the application frame.

See also

wxMenu, Event handling overview

Members

wxMenuBar::wxMenuBar
wxMenuBar::~wxMenuBar
wxMenuBar::Append
wxMenuBar::Check
wxMenuBar::Enable
wxMenuBar::EnableTop
wxMenuBar::FindMenu
wxMenuBar::FindMenuItem
wxMenuBar::FindItem
wxMenuBar::GetHelpString
wxMenuBar::GetLabel
wxMenuBar::GetLabelTop
wxMenuBar::GetMenu
wxMenuBar::GetMenuCount
wxMenuBar::Insert
wxMenuBar::IsChecked
wxMenuBar::IsEnabled
wxMenuBar::Refresh
wxMenuBar::Remove
wxMenuBar::Replace
wxMenuBar::SetHelpString
wxMenuBar::SetLabel
wxMenuBar::SetLabelTop

### wxMenuBar::wxMenuBar

void wxMenuBar(long style = 0)

Default constructor.

void wxMenuBar(int n, wxMenu* menus[], const wxString titles[])

Construct a menu bar from arrays of menus and titles.

Parameters

n

The number of menus.

menus

An array of menus. Do not use this array again - it now belongs to the menu bar.

titles

An array of title strings. Deallocate this array after creating the menu bar.

style

If `wxMB_DOCKABLE` the menu bar can be detached (wxGTK only).

wxPython note: Only the default constructor is supported in wxPython. Use wxMenuBar.Append instead.

### wxMenuBar::~wxMenuBar

void ~wxMenuBar()

Destructor, destroying the menu bar and removing it from the parent frame (if any).

### wxMenuBar::Append

bool Append(wxMenu *menu, const wxString& title)

Adds the item to the end of the menu bar.

Parameters

menu

The menu to add. Do not deallocate this menu after calling Append.

title

The title of the menu.

Return value

TRUE on success, FALSE if an error occurred.

See also

wxMenuBar::Insert

### wxMenuBar::Check

void Check(int id, const bool check)

Checks or unchecks a menu item.

Parameters

id

The menu item identifier.

check

If TRUE, checks the menu item, otherwise the item is unchecked.

Remarks

Only use this when the menu bar has been associated with a frame; otherwise, use the wxMenu equivalent call.

### wxMenuBar::Enable

void Enable(int id, const bool enable)

Enables or disables (greys out) a menu item.

Parameters

id

The menu item identifier.

enable

TRUE to enable the item, FALSE to disable it.

Remarks

Only use this when the menu bar has been associated with a frame; otherwise, use the wxMenu equivalent call.

### wxMenuBar::EnableTop

void EnableTop(int pos, const bool enable)

Enables or disables a whole menu.

Parameters

pos

The position of the menu, starting from zero.

enable

TRUE to enable the menu, FALSE to disable it.

Remarks

Only use this when the menu bar has been associated with a frame.

### wxMenuBar::FindMenu

int FindMenu(const wxString& title) const

Returns the index of the menu with the given title or wxNOT_FOUND if no such menu exists in this menubar. The title parameter may specify either the menu title (with accelerator characters, i.e. `"&File"`) or just the menu label (`"File"`) indifferently.

### wxMenuBar::FindMenuItem

int FindMenuItem(const wxString& menuString, const wxString& itemString) const

Finds the menu item id for a menu name/menu item string pair.

Parameters

menuString

Menu title to find.

itemString

Item to find.

Return value

The menu item identifier, or wxNOT_FOUND if none was found.

Remarks

Any special menu codes are stripped out of source and target strings before matching.

### wxMenuBar::FindItem

wxMenuItem * FindItem(int id, wxMenu **menu = NULL) const

Finds the menu item object associated with the given menu item identifier.

Parameters

id

Menu item identifier.

menu

If not NULL, menu will get set to the associated menu.

Return value

The found menu item object, or NULL if one was not found.

### wxMenuBar::GetHelpString

wxString GetHelpString(int id) const

Gets the help string associated with the menu item identifer.

Parameters

id

The menu item identifier.

Return value

The help string, or the empty string if there was no help string or the menu item was not found.

See also

wxMenuBar::SetHelpString

### wxMenuBar::GetLabel

wxString GetLabel(int id) const

Gets the label associated with a menu item.

Parameters

id

The menu item identifier.

Return value

The menu item label, or the empty string if the item was not found.

Remarks

Use only after the menubar has been associated with a frame.

### wxMenuBar::GetLabelTop

wxString GetLabelTop(int pos) const

Returns the label of a top-level menu.

Parameters

pos

Position of the menu on the menu bar, starting from zero.

Return value

The menu label, or the empty string if the menu was not found.

Remarks

Use only after the menubar has been associated with a frame.

See also

wxMenuBar::SetLabelTop

### wxMenuBar::GetMenu

wxMenu* GetMenu(int menuIndex) const

Returns the menu at menuIndex (zero-based).

### wxMenuBar::GetMenuCount

int GetMenuCount() const

Returns the number of menus in this menubar.

### wxMenuBar::Insert

bool Insert(size_t pos, wxMenu *menu, const wxString& title)

Inserts the menu at the given position into the menu bar. Inserting menu at position 0 will insert it in the very beginning of it, inserting at position GetMenuCount() is the same as calling Append().

Parameters

pos

The position of the new menu in the menu bar

menu

The menu to add. wxMenuBar owns the menu and will free it.

title

The title of the menu.

Return value

TRUE on success, FALSE if an error occurred.

See also

wxMenuBar::Append

### wxMenuBar::IsChecked

bool IsChecked(int id) const

Determines whether an item is checked.

Parameters

id

The menu item identifier.

Return value

TRUE if the item was found and is checked, FALSE otherwise.

### wxMenuBar::IsEnabled

bool IsEnabled(int id) const

Determines whether an item is enabled.

Parameters

id

The menu item identifier.

Return value

TRUE if the item was found and is enabled, FALSE otherwise.

### wxMenuBar::Refresh

void Refresh()

Redraw the menu bar

### wxMenuBar::Remove

wxMenu * Remove(size_t pos)

Removes the menu from the menu bar and returns the menu object - the caller is reposnbile for deleting it. This function may be used together with wxMenuBar::Insert to change the menubar dynamically.

See also

wxMenuBar::Replace

### wxMenuBar::Replace

wxMenu * Replace(size_t pos, wxMenu *menu, const wxString& title)

Replaces the menu at the given position with another one.

Parameters

pos

The position of the new menu in the menu bar

menu

The menu to add.

title

The title of the menu.

Return value

The menu which was previously at the position pos. The caller is responsible for deleting it.

See also

wxMenuBar::Insert, wxMenuBar::Remove

### wxMenuBar::SetHelpString

void SetHelpString(int id, const wxString& helpString)

Sets the help string associated with a menu item.

Parameters

id

Menu item identifier.

helpString

Help string to associate with the menu item.

See also

wxMenuBar::GetHelpString

### wxMenuBar::SetLabel

void SetLabel(int id, const wxString& label)

Sets the label of a menu item.

Parameters

id

Menu item identifier.

label

Menu item label.

Remarks

Use only after the menubar has been associated with a frame.

See also

wxMenuBar::GetLabel

### wxMenuBar::SetLabelTop

void SetLabelTop(int pos, const wxString& label)

Sets the label of a top-level menu.

Parameters

pos

The position of a menu on the menu bar, starting from zero.

label

The menu label.

Remarks

Use only after the menubar has been associated with a frame.

See also

wxMenuBar::GetLabelTop