Using menus
You can use menus in two ways:
- Place them in the
menu bar of a window - Display a menu as a popup 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:
-
Click the Open button in the PowerBar,
select the window you want to associate the menu with, and open
the window. -
In the Properties view for the window, enter the
name of the menu in the MenuName textbox on the General tab page.or
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. -
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:
|
1 |
<i>menu.menu item</i> |
You must always fully qualify the menu item with the name
of the menu.
When referring to a menu item in a dropdown 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, code:
|
1 |
m_menu.m_file.m_open.Enabled |
Changing a window’s menu during execution
You can use the ChangeMenu function in a script to change
the menu associated with a window during execution.
For information about ChangeMenu, see the PowerScript
Reference
.
Displaying popup menus
To display a popup 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 popup menu at the current pointer
position (assuming menu m_appl is already associated with
the window):
|
1 |
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 popup 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):
|
1 |
m_new mymenu<br /><br />mymenu = create m_new<br />mymenu.m_file.PopMenu(PointerX(), PointerY()) |
For more information
For complete information about the PopMenu function, see the PowerScript Reference
.