Add Menu Items at Run Time
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.
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.
DO dynamic.mpr
Then, for each item in the list, the code defines a menu item with the prompt and message text.
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.
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
Coordinate Menu Items and Toolbar Buttons | Solutions Samples