Using menus in your applications

You can use menus in two ways:

  • Place them in the menu bar of a window

  • Display a menu as a pop-up menu

Adding a menu bar to a window

To have a menu bar display when a window is opened by a user, you associate a menu with the window in the Window painter.

To associate a menu with a window

  1. Click the Open button in the PowerBar, select the window with which you want to associate the menu, and open the window.

  2. Do one of the following:

    • In the Properties view for the window, enter the name of the menu in the MenuName text box on the General tab page.

    • Click the Browse button and select the menu from the Select Object dialog box, which lists all menus available to the application.

    • In the Select Object dialog box, you can search for a menu by clicking the Browse button.

  3. Click Save to associate the selected menu with the window.

Identifying menu items in window scripts

You reference menu items in scripts in windows and controls using the following syntax:

menu.menu item

You must always fully qualify the menu item with the name of the menu.

When referring to a menu item in a drop-down or cascading menu, you must specify each menu item on the path to the menu item you are referencing, separating the names with periods.

For example, to refer to the Enabled property of menu item m_open, which is under the menu bar item m_file in the menu saved in the library as m_menu, use:

m_menu.m_file.m_open.Enabled

Changing a window's menu at runtime

You can use the ChangeMenu function in a script to change the menu associated with a window at runtime.

Displaying pop-up menus

To display a pop-up menu in a window, use the PopMenu function to identify the menu and the location at which you want to display the menu.

If the menu is associated with the window

If the menu is currently associated with the window, you can simply call the PopMenu function.

The following statement in a CommandButton script displays m_appl.m_help as a pop-up menu at the current pointer position, assuming menu m_appl is already associated with the window:

m_appl.m_help.PopMenu(PointerX(), PointerY())

If the menu is not associated with the window

If the menu is not already associated with the window, you must create an instance of the menu before you can display it as a pop-up menu.

The following statements create an instance of the menu m_new, then pop up the menu mymenu.m_file at the pointer location, assuming m_new is not associated with the window containing the script:

m_new mymenu
mymenu = create m_new
mymenu.m_file.PopMenu(PointerX(), PointerY())