ON SELECTION MENU Command 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