Links are not active on this page.
 Add Menu Items at Run Time Sample

File: ...\Samples\Solution\Menus\Fillmenu.scx

This sample illustrates adding menu items to a menu at run time.

The menu definition in this sample is defined in the Menu Designer, with a single prompt and an empty submenu named empty_pop.

Code is included to be executed when a user chooses any item in the menu.

 CopyCode imageCopy Code
PROCEDURE takeaction(cPrompt)
#DEFINE MSG_LOC "You chose " + cPrompt + "." 
IF cPrompt = "Release this menu"
   RELEASE PAD dynmenu of _MSYSMENU
ELSE
   WAIT WINDOW MSG_LOC TIMEOUT 1
ENDIF

The code associated with the Click event of cmdRefresh on the form runs the menu.

 CopyCode imageCopy Code
DO dynamic.mpr

Then, for each item in the list, the code defines a menu item with the prompt and message text.

 CopyCode imageCopy Code
FOR i = 1 TO THISFORM.lstMenu.ListCount
   DEFINE BAR i OF empty_pop PROMPT (ALLTRIM(THISFORM.lstMenu.List(i,1))) ;
      MESSAGE (THISFORM.lstMenu.List(i,2))
ENDFOR

There is also code to provide the prompt to make it possible for a user to release the menu.

 CopyCode imageCopy Code
DEFINE BAR i + 1 OF empty_pop PROMPT "\-"
DEFINE BAR i + 2 OF empty_pop PROMPT "Release this menu" ;
   MESSAGE "Remove the Dynamic Items menu from the menu bar."

See Also