Pop-up menus

If a top-level menu is given the style flag WS_POPUP, it becomes a popup menu, that can be set to appear anywhere within the parent window, or on the program’s system tray icon.

image0

The illustration shows a popup menu that has been opened by right-clicking on a table row.

The move cursor | at command is used to specify the position at which the menu is to pop up, followed by the open command to make the menu appear. The most common method is a right mouse click (and release) by the user, causing the EV_RIGHT_MOUSE_UP event to be generated for the window or control clicked on. EV_RIGHT_MOUSE_UP is not enabled by default, and must be enabled by means of the event_enable clause, e.g.:

event_enable = EV_DEFAULT | EV_RIGHT_MOUSE_UP

The EV_RIGHT_MOUSE_UP event sends arguments that indicate the position of the right mouse click relative to the effective parent of the control clicked on. The effective parent is the highest window in the parent window chain that has no further parent, or that has the window style WS_OWNED. This is the window in which a popup menu should be opened.

If the user selects an item from the popup menu, the menu closes and the item’s select function is called.

If the user clicks outside the menu, it closes without calling a select function.

Note

The hide command has no effect on a popup menu item, since it only works on a created object and a popup menu is re-created every time it is opened. To hide a menu item on a popup menu, assign the style flag WS_INVISIBLE to the item before opening the menu.


EXAMPLE

The following code fragments illustrate the use of a popup menu.

+window MyWin ... {
     ...
     event_enable = EV_DEFAULT | EV_RIGHT_MOUSE_UP
     ...
     menu PopUp {
         style = WS_POPUP
         ...
     }
 }

 !function MyWinEvent(EventCode, Object, XPos, YPos) {
     switch EventCode {
     ...
     case == EV_RIGHT_MOUSE_UP:
         move cursor to XPos,YPos in MyWin
         open MyWin.PopUp
         return
     }
 }

RELATED TOPICS

Menus

Window events and functions

Menu events and functions

The event_enable clause

system tray icon