Condividi tramite


ON SELECTION MENU Command

Specifies a command that executes when you choose any menu title on a menu bar.

ON SELECTION MENU MenuBarName | ALL [Command]

Parameters

  • MenuBarName
    Specifies the name of the menu bar to which you assign a command. The command executes when you choose any menu title from the menu bar. You can specify the name of a user-defined menu bar created with DEFINE MENU or the Microsoft Visual FoxPro system menu bar _MSYSMENU.
  • ALL
    Executes a command when you choose any menu title from any menu bar.
  • Command
    Specifies the command to execute when you choose a menu title. Use ON SELECTION MENU without a command to release a command assigned to a menu bar.

Remarks

When you create and activate a menu bar, place ON SELECTION MENU between DEFINE MENU and ACTIVATE MENU.

Use ON SELECTION PAD to execute a command when you choose a specific menu item. ON SELECTION PAD takes precedence over ON SELECTION MENU. Use ON PAD to activate a menu or menu bar when you choose a specific menu title.

Use ON SELECTION MENU without a command to release a command assigned to a menu bar.

Example

In the following example, ON SELECTION MENU is used to execute a procedure when a menu title is chosen from the Visual FoxPro system menu bar.

The current system menu bar is saved to memory with SET SYSMENU SAVE and all system menu titles are removed with SET SYSMENU TO.

DEFINE PAD creates several system menu titles. When you choose a menu title, the choice procedure assigned to the menu bar with ON SELECTION MENU executes. The choice procedure displays the name of the menu title you choose and the name of the menu bar. If you choose the Exit menu title, the original Visual FoxPro system menu is restored.

** Name this program ONMENU.PRG ** CLEAR SET SYSMENU SAVE SET SYSMENU TO DEFINE PAD padSys OF _MSYSMENU PROMPT '<System' COLOR SCHEME 3 ; KEY ALT+S, '' DEFINE PAD padEdit OF _MSYSMENU PROMPT '<Edit' COLOR SCHEME 3 ; KEY ALT+E, '' DEFINE PAD padRecord OF _MSYSMENU PROMPT '<Record' COLOR SCHEME 3 ; KEY ALT+R, '' DEFINE PAD padWindow OF _MSYSMENU PROMPT '<Window' COLOR SCHEME 3 ; KEY ALT+W, '' DEFINE PAD padReport OF _MSYSMENU PROMPT 'Re<ports' COLOR SCHEME 3 KEY ALT+P, '' DEFINE PAD padExit OF _MSYSMENU PROMPT 'E<xit' COLOR SCHEME 3 ; KEY ALT+X, '' ON SELECTION MENU _MSYSMENU ; DO choice IN onmenu WITH PAD( ), MENU( ) PROCEDURE choice PARAMETER gcPad, gcMenu WAIT WINDOW 'You chose ' + gcPad + ; ' from menu ' + gcMenu NOWAIT IF gcPad = 'PADEXIT' SET SYSMENU TO DEFAULT ENDIF

See Also

ACTIVATE MENU | DEFINE MENU | ON PAD | ON SELECTION PAD