Directives
POPUP_MENU Create Popup Menu
   
Format POPUP_MENU [@(col,ln)], list$, [strvar$|numvar]
 
Where:
 
  @(col,ln) Numeric expressions. The optional column and line position on the current window where the menu will appear.
  list$ Menu structure and elements. String expressions. Maximum 2047
    elements. A bitmap/icon can be included for each element.
  numvar Name of variable that receives the numeric value of the selection made.
  strvar$ Name of variable that receives the string containing the selection sequence of characters selected.
   
Description Use the POPUP_MENU directive to create and process floating menus. A popup menu "pops up" on top of the current window when you right-click the mouse while the pointer is over a control, such as a button, multi-line, or list box. Once a popup menu is created and assigned to a control, it remains invisible until the user right-clicks the mouse button over the enabled component. In a popup menu, a default option may be specified.

Popup Menu Definition

POPUP_MENU definition uses a format similar to the MENU_BAR Directive:

  • Each menu group is enclosed by square brackets.
  • Each item in a group is separated by a comma.
  • Each item's selection character (hot key) is preceded by an '&' (ampersand).
  • Each sub-menu group is prefixed with its item ID.

Numeric values are assigned to each entry in the menu definition. By default, the first entry has the value ‘', the second ‘', etc. This value can be overridden by placing an equal sign and numeric value after the menu item text; e.g.,

"F:[&Open,&Save,&Quit=4]"

Quit would have a value of four. In addition, the starting numeric value can be changed or reset by placing a # followed by the new starting point within the menu definition string outside of group definitions. When setting a new starting value, the next menu selection will be assigned a number that is one more than the starting point; e.g.,

"[&File,&Quit],#1000,F:[&Open,&Save,&Rename]"

This defines File as one, uit as two, File-pen as 1001, File-ave as 1002, and File-ename as 1003. Accelerator keys should be unique for each selection on a given sub-menu within a group. While the use of duplicate accelerator keys is permitted, it is difficult to determine which selection was made by using just the character strings.

Menu items can be disabled, displayed in bold or with a checkmark, by placing a "D", "B", or "C" after the = (equal sign) and before the value to return; e.g.,

m$="[&One=1,&Two=C2,&Three=D3,&Four=BC4]"
POPUP_MENU m$,answer$

The resulting menu shows "Two" checked, "Three" disabled, and "Four" both bolded and checked.
 

Popup Menu Assignment

A POPUP_MENU can be associated with buttons, check boxes, drop boxes, grids, list boxes, multi-lines, radio buttons and tristate boxes. The directives that control these objects, include a MNU= option that defines the CTL number that will be generated when the user right-clicks on the control.

Bitmaps and Icons

Images can be included for each item in the menu. Enclose the image name in curly braces and place it in the menu definition just prior to the specific item text; e.g.,
 
"-[&File],F:[&Open=1001,{!Stop}&Stop=1002]"

Use a leading exclamation point (!) to identify the image as internal, or specify the relative path and filename to access an image file that is external. For more information on internal/external images and recognized image file types, refer to Displaying Bitmaps/Icons.

   
Two-Tone Effects The POPUP_MENU directive supports the use of two optional parameters for defining background and left edge colours in menus (similar to MS Office applications):
LEFT(arg) Background colour for the bitmap portion of the menu. Must be placed outside "[...]" menu definitions.
FILL(arg) Background colour for the right/text side. If placed outside "[...]" menu definitions it will serve as the default colour for all menuitems. If placed within "[...]", it will be considered the colour associated with a specific menu item.

The arg value is defined using the same format as the Colour Properties.

In the following example, the RGB colour 200,200,200 is used for the left edge of all entries in this menu

POPUP_MENU "LEFT(RGB:200,200,200),[&File,&Edit,&Help],F:[...."

The next example uses the RGB colour 255,255,150 as the background colour for all of the text portion of the menu.

POPOP_MENU 10,"FILL(RGB:255,255,150),[&File,&Edit,&Help],F:[...."



*Note* The system-supplied Cut, Copy, Paste, and Delete menu items will adhere to the FILL(arg) and LEFT(arg) definitions for the menu.


See Also MENU_BAR Directive
BUTTON Control Button,
CHECK_BOX Control Check Box
DROP_BOX Control Drop Box
GRID Control Grid
LIST_BOX Control List Box
MULTI_LINE Control Multi-Line Input
RADIO_BUTTON Control Radio Button
TRISTATE_BOX Control Tristate Box
   
Example This popup menu returns a numeric value assigned by the menu bar definition

0020 print 'CS',; list 0030,
0030 check_box 100,@(50,10,10,2)="{}Popup Menu",opt="P",mnu=101
0040 obtain *
0050 if ctl=4 then stop
0060 if ctl<>101 then goto 0040
0070 mdef$="[&File,&Edit,E&xit=4],F:[&Open=10,&Save=D20], E:[C&ut=30,&Copy=40,&Paste=50]"
0080 popup_menu @(58,12),mdef$,x
0090 print "Selected: ",x
0100 if x=4 then stop
0110 goto 0040