In this section, you complete the menu item for the sample window.

To define a CHOOSE trigger for the Help About item:

DO:
  DEFINE VARIABLE cChildren AS CHARACTER NO-UNDO.
  DEFINE VARIABLE hChild AS HANDLE NO-UNDO.  
  hChild = SUB-MENU m_Navigation:FIRST-CHILD IN MENU m_CustWin.
  DO WHILE VALID-HANDLE(hChild):
    cChildren = cChildren + hChild:LABEL + ",".
    hChild = hChild:NEXT-SIBLING.
  END.
  
  MESSAGE "Here's some information about this menu:" SKIP
    "The menu's owner is " MENU m_CustWin:OWNER:TITLE SKIP
    "This item's label is "
      MENU-ITEM m_Help_About:LABEL IN MENU m_CustWin SKIP
    "This item's parent object is "
      MENU-ITEM m_Help_About:PARENT:LABEL IN MENU m_CustWin SKIP
    "The Navigation submenu's children are " cChildren.
END.

This displays some information about the menu to show you this information:

  • The menu itself has the window as an OWNER, not a PARENT.
  • Each menu item has attributes, such as its LABEL, that you can query and set as you can for other objects.
  • Each menu item and submenu has a PARENT attribute that leads you up through the menu hierarchy.
  • Each parent object has a FIRST-CHILD attribute. Using that and the NEXT-SIBLING attribute of each child, you can identify all the objects at any level in the menu tree.

This figure shows what you see when you run the window and select Help > Help About.

Figure 1. Sample menu information message

Look at the code

Now look at the statements the AppBuilder generated when you built the menu. You can also see this code in the Code Preview window.

First the code defines each submenu:

/* Menu Definitions                                                     */
DEFINE SUB-MENU m_Navigation 
       MENU-ITEM m_First        LABEL "First"          ACCELERATOR "CURSOR-UP"
       MENU-ITEM m_Next         LABEL "Next"           ACCELERATOR "CURSOR-RIGHT"
       MENU-ITEM m_Prev         LABEL "Prev"           ACCELERATOR "CURSOR-LEFT"
       MENU-ITEM m_Last         LABEL "Last"           ACCELERATOR "CURSOR-DOWN".

DEFINE SUB-MENU m_Buttons 
       MENU-ITEM m_No_FirstLast LABEL "No &First/Last"
       MENU-ITEM m_No_Prev      LABEL "No &Prev"      
       MENU-ITEM m_Allow_All    LABEL "Allow &All"    
       RULE
       SUB-MENU  m_Navigation   LABEL "Navigation"    .

DEFINE SUB-MENU m_Show 
       MENU-ITEM m_Warehouse_Info LABEL "Warehouse Info"
              TOGGLE-BOX.

DEFINE SUB-MENU m_Help 
       MENU-ITEM m_Help_About   LABEL "Help About"    .

Once all the submenus are defined, the code defines the menu bar itself:

DEFINE MENU m_CustWin MENUBAR
       SUB-MENU  m_Buttons      LABEL "Buttons"       
       SUB-MENU  m_Show         LABEL "Show"          
       SUB-MENU  m_Help         LABEL "Help"          .

After the window is defined, the menu bar is attached to the window:

ASSIGN {&WINDOW-NAME}:MENUBAR    = MENU m_CustWin:HANDLE.