IMenuBar

The IMenuBar class represents a menu bar for frame windows.
Note: You can add a menu bar to a frame window without using the IMenuBar class by specifying the style IFrameWindow::menuBar when you construct an IFrameWindow object.

AIX Considerations

The Open Class Library adds a Motif callback routine to all menu bars for processing selected menu bar items.

Windows Considerations

To support menus loaded from a resource file, IMenuBar classes have the following requirements:


IMenuBar - Member Functions and Data by Group

Constructors & Destructor

You can construct and destruct objects of this class. You cannot copy or assign IMenuBar objects because the copy constructor and assignment operator are private functions.


[view class]
~IMenuBar
public:
virtual ~IMenuBar()

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
IMenuBar


Overload 1
public:
IMenuBar( IFrameWindow* owner, const Style& style = defaultStyle ( ) )

Creates an empty menu bar or a wrapper for an existing IFrameWindow menu bar. Use this constructor to create the following:

Exception

IInvalidParameter owner is 0. You must specify a valid IFrameWindow as the owner for the menu bar.
IInvalidRequest The style specified is invalid. Specify one of the styles IMenuBar::wrapper or IMenuBar::empty, but not both.
IInvalidRequest The style IMenuBar::wrapper was specified, but the frame window has no menu bar. Verify that the IFrameWindow::menuBar style was specified when the frame was created and that owner is the correct IFrameWindow.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Overload 2
public:
IMenuBar(const IResourceId& menuResId, IFrameWindow* owner)

Creates a menu bar with a menu resource ID and a frame window owner. Use this constructor to create a menu bar for a frame window with a menu resource from your resource library.

Exception

IInvalidParameter owner is 0. You must specify a valid IFrameWindow as the owner for the menu bar.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes

Windows Considerations

To support menus loaded from a resource file, IMenuBar classes have the following requirements:

  • Menu resources must be defined using the MENUEX keyword.
  • Unique IDs must be provided for all pop-up menu items, indicated by the POPUP keyword.

Replacing Menus

You can replace the menu currently being used on the menu bar with another menu.


[view class]
setMenu

Sets or changes the menu bar to the specified menu. The previous menu bar is destroyed.


Overload 1
public:
virtual IMenuBar& setMenu(const IMenuHandle& menuHandle)

The new menu is specified by its menu handle.

Supported Platforms

Windows OS/2 AIX
Yes No No


Overload 2
public:
virtual IMenuBar& setMenu(const IResourceId& menuResId)

The new menu is specified by its menu id.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes

Windows Considerations

To support menus loaded from a resource file, IMenuBar classes have the following requirements:

  • Menu resources must be defined using the MENUEX keyword.
  • Unique IDs must be provided for all pop-up menu items, indicated by the POPUP keyword.

Styles

IMenuBar defines objects of the nested class IMenuBar::Style. You can use these styles with the function IMenuBar::setDefaultStyle and a constructor for IMenuBar.


[view class]
defaultStyle
public:
static Style defaultStyle()

Returns the default style. The default style is IMenuBar::classDefaultStyle unless you have changed it using IMenuBar::setDefaultStyle.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
setDefaultStyle
public:
static void setDefaultStyle(const Style& style)

Sets the default style for all subsequent menu bars.

This member function is not thread safe. In a multithreaded application, it should only be called when a conflict is not possible. A conflict can arise if you set the default style on one thread at the same time that it is being queried on another. In this situation, the query would take place while the style is in an unknown state.

When you create a window class and do not specify window styles in the constructor, the Open Class Library queries the default style. Therefore, the only safe place to call this member function is when no other application threads that create windows are active.

Another way to avoid a conflict in a multithreaded application is to specify window styles on window construction, rather than calling this member function.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
classDefaultStyle
public:
static const Style classDefaultStyle

Specifies the original default style for this class, which is IMenuBar::empty.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
empty
public:
static const Style empty

Creates a menu with no items. You can dynamically populate the menu using functions from IMenu and ISubmenu. You cannot specify this style with the IMenuBar::wrapper style.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
wrapper
public:
static const Style wrapper

Specifies that the menu bar is a wrapper for an IFrameWindow menu bar, which you previously created using the style IFrameWindow::menuBar. You cannot specify this style with the IMenuBar::empty style.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


IMenuBar - Inherited Member Functions and Data

Inherited Public Functions

IMenu
INotifier
IStandardNotifier

Inherited Public Data

INotifier
IMenu

Inherited Protected Functions

INotifier
IStandardNotifier
IMenu

Inherited Protected Data