popupMenu()

Activating a context-sensitive menu by means of right-clicking.

In the user interface you can activate a context menu also through left-click.

Synopsis

int popupMenu(dyn_string text, int &answer);

Parameters

Parameter Description
text Structure of the menu, see below
answer Return variable

Return value

In the event of an error, the function returns -1 otherwise, 0.

Error

Wrong or missing parameters.

Description

A pop-up menu opens for a user to select from options. The selected option will be returned by the variable answer. Each line in the transferred string must begin with a keyword. The following keywords are allowed:

Keyword Description
PUSH_BUTTON

This keyword defines a menu item. The text to be displayed follows the word PUSH_BUTTON and is followed by the return value (int) that will be returned to the variable "answer" after this button has been clicked. The last value defines whether an entry is active or inactive. The value '1' indicates that an entry is active and can be clicked on. The value '0' results in this value being set to inactive and therefore cannot be clicked on.

Example: "PUSH_BUTTON, test field, 15, 1" would be an entry with the text "test field" that returns 15 as the return value and is active.

SEPARATOR The keyword SEPARATOR has no parameters and displays a horizontal separation line in a menu.
CHECK_BUTTON

The functions popupMenu and popupMenuXY include the item "CHECK_BUTTON" (for example, "CHECK_BUTTON, check10, 10, 1, 1") and can display a check box.

Object Name Return value Enabled Checked

"CHECK_BUTTON, check10, 10, 1, 1",

If you want to disable a check box, set the "Checked", meaning the fifth parameter, to 0.

Figure: check box

CASCADE_BUTTON

This field generates a branch at a lower menu level. CASCADE_BUTTON has two parameters: name and activity. Activity is the same as for PUSH_BUTTON. The specified name serves a double role: First it is used as the text for a branch. Second the name is immediately available as a keyword. All the menu items following this keyword are then found in the lower level.

The text for a menu with the structure :

Button 1

level 2 -> Button 2

Button 3

would therefore be "PUSH_BUTTON,Button 1,1,1",

"CASCADE_BUTTON,level 2,1",

"PUSH_BUTTON,Button 3,3,1",

"level 2",

"PUSH_BUTTON,Button 2,2,1"

Note, though, after "level 2" it will no longer be possible to define a first-level element.

Example

The following script script generates a menu with two levels after right-clicking. The entries text1, text2 and text3 are in the first level. The entry level2 will also be displayed. If this entry is clicked, the level below will be set to visible.

main()
{
  dyn_string txt;
  int answer;
  txt = makeDynString("PUSH_BUTTON, text1, 1, 1",
            "PUSH_BUTTON, text2, 2, 1",
            "SEPARATOR",
// separating line
            "CASCADE_BUTTON, Level 2, 1",
// branch
            "PUSH_BUTTON, text3, 3, 1",
            "Level 2",
// from here level 2
            "PUSH_BUTTON, text4, 4, 0",
            "PUSH_BUTTON, text5, 5, 1");

  popupMenu(txt, answer);
  DebugN(answer);
}

Assignment

Graphics

Availability

UI