Progress
Programming
Handbook


Static Menu Bars

The following sections describe how to set up a menu bar. They contain sample code that generates the following menu bar.

Setting Up a Static Menu Bar

Setting up a static menu bar is a three-part process:

  1. Define the pull-down submenus.
  2. Define the menu bar itself.
  3. Assign the menu bar to a window.

The following sections describe this process in greater detail.

Defining Pull-down Submenus

To generate a submenu, you use the DEFINE SUB–MENU statement. Each submenu must have a unique name. Use the MENU–ITEM phrase to specify menu items, and use the LABEL option to define the text for the menu item. If you omit LABEL, Progress displays the item handle name by default. Progress lays out the menu items consecutively in a top-to-bottom order. The following code fragment defines three submenus and their menu items.

DEFINE SUB-MENU topic
  MENU-ITEM numbr    LABEL "Cust-num"
  MENU-ITEM addr     LABEL "Address"
  MENU-ITEM othrinfo LABEL "Other".

DEFINE SUB-MENU move
  MENU-ITEM forward  LABEL "Next" ACCELERATOR "PAGE-DOWN"
  MENU-ITEM backward LABEL "Prev" ACCELERATOR "UP".

DEFINE SUB-MENU quitit
  MENU-ITEM quit LABEL "E&xit". 

The ACCELERATOR option specifies a key or key combination that the user can use to select a menu item without having to pull down the menu. For more information on accelerators, see the "Menu Item Accelerators" section.

The ampersand (&) before the letter x in "E&xit" causes x to be underlined when the menu is displayed. The letter x is called a mnemonic. A mnemonic provides a way to access menu items from the keyboard. For more information on mnemonics, see the "Menu Mnemonics" section.

To generate a help submenu, add the SUB–MENU–HELP phrase to the DEFINE SUB–MENU statement, as shown below.

DEFINE SUB-MENU userhelp SUB-MENU-HELP
  MENU-ITEM message    LABEL "Recent Messages"
  MENU-ITEM keybd      LABEL "Keyboard"
  MENU-ITEM command    LABEL "Menu Commands". 

For more information on the DEFINE SUB–MENU statement, see the Progress Language Reference .

Defining a Menu Bar

To generate a menu bar, you use the DEFINE MENU statement. You must explicitly specify the MENUBAR phrase. You can add menu items and submenus to the menu bar.

In the following code, you assign the three previously defined submenus to the menu bar with the SUB–MENU phrase. You use the LABEL option to define the text for the submenu. Progress lays out the submenus consecutively in left-to-right order on the menu bar.

DEFINE MENU mbar MENUBAR
  SUB-MENU topic    LABEL "Topic"
  SUB-MENU move     LABEL "Move"
  SUB-MENU quitit   LABEL "E&xit"
  SUB-MENU userhelp LABEL "Help". 

NOTE: You can add submenus or menu items to existing dynamic menu structures at any time. Progress appends the newly added widgets to the end of the list. See the "Dynamic Menus" section.

For more information on the DEFINE MENU statement, see the Progress Language Reference .

Assigning a Menu Bar to a Window

Now that you have set up a menu bar, you need to assign it to a window. You do so by setting the window’s MENUBAR attribute equal to the handle of the menu. For example, if you are using the current window or default window, you can refer to it by using the CURRENT–WINDOW or DEFAULT–WINDOW system handle.

ASSIGN DEFAULT-WINDOW:MENUBAR  = MENU mbar:HANDLE. 

If you are using a window that your application has created, you can refer to the window‘s widget handle. See the following code fragment. At the end of the code, delete the window with the DELETE WIDGET statement.

DEFINE VARIABLE mwin AS WIDGET-HANDLE.
          .
          .
          .
CREATE WINDOW mwin
  ASSIGN MENUBAR = MENUmbar:HANDLE.
          .
          .
          .
DELETE WIDGET mwin. 

Example of a Menu Bar with Pull-down Submenus

The p-bar.p procedure that follows contains most of the sample definition codes used in the previous sections. The procedure defines a menu bar, mbar, which contains three pull-down submenus. The handle of mbar is assigned to the current window. The ON statements define triggers that execute when you select the corresponding menu items.

p-bar.p
DEFINE SUB-MENU topic
    MENU-ITEM numbr  LABEL "Cust. Number"
    MENU-ITEM addr LABEL "Address"
    MENU-ITEM othrinfo LABEL "Other".
    
DEFINE SUB-MENU move  
    MENU-ITEM forward    LABEL "NextRec" ACCELERATOR "PAGE-DOWN"
    MENU-ITEM backward    LABEL "PrevRec" ACCELERATOR "PAGE-UP".
    
DEFINE SUB-MENU quitit
    MENU-ITEM quititem LABEL "E&xit".
  
DEFINE MENU mbar     MENUBAR
    SUB-MENU topic   LABEL "Topic"
    SUB-MENU move    LABEL "Move"
    SUB-MENU quitit  LABEL "E&xit".

FIND FIRST customer.
DISPLAY customer.name LABEL "Customer Name" WITH FRAME name-frame.

ON CHOOSE OF MENU-ITEM numbr
    DISPLAY customer.cust-num WITH FRAME num-frame ROW 6.

ON CHOOSE OF MENU-ITEM addr
    DISPLAY customer.address customer.address2 customer.city 
       customer.state customer.country customer.postal-code
       WITH FRAME addr-frame NO-LABELS COLUMN 25 ROW 6.

ON CHOOSE OF MENU-ITEM othrinfo
    DISPLAY customer EXCEPT name cust-num address 
     address2 city state country postal-code
     WITH FRAME oth-frame SIDE-LABELS ROW 11. 
ON CHOOSE OF MENU-ITEM forward
  DO:
     HIDE ALL NO-PAUSE.
     CLEAR FRAME name-frame.
     FIND NEXT customer NO-ERROR.
     IF AVAILABLE(customer)
     THEN DISPLAY customer.name WITH FRAME name-frame. 
  END.
    
ON CHOOSE OF MENU-ITEM backward
  DO:
     HIDE ALL NO-PAUSE.
     CLEAR FRAME name-frame.
     FIND PREV customer NO-ERROR.
     IF AVAILABLE(customer)
     THEN DISPLAY customer.name WITH FRAME name-frame.
  END.   
    
ASSIGN CURRENT-WINDOW:MENUBAR = MENU mbar:HANDLE.

WAIT-FOR CHOOSE OF MENU-ITEM quititem. 

When you run this code, you see a menu bar at the top of the window and a frame that displays the name of the first customer. The menu bar contains three titles: Topic, Move, and Exit. You can select each title, one at a time, and pull down its menu to select a menu item.

The Exit menu has only one item. When you choose that item, the procedure ends.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095