BAR( ) Function Example

The following example uses BAR( ) to pass the number of a menu item to a procedure. The current system menu bar is saved to memory with SET SYSMENU SAVE, and then all system menu titles are removed with SET SYSMENU TO.

Two menu titles are created with DEFINE PAD; DEFINE POPUP is used to create a menu for each menu title. DEFINE BAR is used to create items on each menu. When you choose a menu title, ON PAD uses ACTIVATE POPUP to activate the corresponding menu.

When you choose an item from a menu, ON SELECTION POPUP uses BAR( ) and POPUP( ) to pass the item number and menu title to the choice procedure. The choice procedure displays the number of the chosen item and the name of the menu containing the item, and the original Visual FoxPro system menu is restored with SET SYSMENU TO DEFAULT.

*** Name this program BAR_EXAM.PRG ***
CLEAR
SET SYSMENU SAVE
SET SYSMENU TO
DEFINE PAD padConv OF _MSYSMENU ;
   PROMPT '\<Conversions' COLOR SCHEME 3 ;
   KEY ALT+C, ''
DEFINE PAD padCard OF _MSYSMENU ;
   PROMPT 'Card \<Info' COLOR SCHEME 3 ;
   KEY ALT+I, ''
ON PAD padConv OF _MSYSMENU ACTIVATE POPUP popConv
ON PAD padCard OF _MSYSMENU ACTIVATE POPUP popCard
DEFINE POPUP popConv MARGIN RELATIVE COLOR SCHEME 4
DEFINE BAR 1 OF popConv PROMPT 'Ar\<ea' KEY CTRL+E, '^E'
DEFINE BAR 2 OF popConv PROMPT '\<Length' ;
   KEY CTRL+L, '^L'
DEFINE BAR 3 OF popConv PROMPT 'Ma\<ss' ;
   KEY CTRL+S, '^S'
DEFINE BAR 4 OF popConv PROMPT 'Spee\<d' ;
   KEY CTRL+D, '^D'
DEFINE BAR 5 OF popConv PROMPT '\<Temperature' ;
   KEY CTRL+T, '^T'
DEFINE BAR 6 OF popConv PROMPT 'T\<ime' ;
   KEY CTRL+I, '^I'
DEFINE BAR 7 OF popConv PROMPT 'Volu\<me' ;
   KEY CTRL+M, '^M'
*** Here is where the POPCONV menu uses the BAR( ) function
*** to pass a bar number to the procedure called choice below.
ON SELECTION POPUP popConv;
   DO choice IN bar_exam WITH BAR( ), POPUP( )
DEFINE POPUP popCard MARGIN RELATIVE COLOR SCHEME 4
DEFINE BAR 1 OF popCard PROMPT '\<View Charges' ;
   KEY ALT+V, ''
DEFINE BAR 2 OF popCard PROMPT 'View \<Payments' ;
   KEY ALT+P, ''
DEFINE BAR 3 OF popCard PROMPT 'Vie\<w Users' ;
   KEY ALT+W, ''
DEFINE BAR 4 OF popCard PROMPT '\-'
DEFINE BAR 5 OF popCard PROMPT '\<Charges ';
   KEY ALT+C
DEFINE BAR 6 OF popCard PROMPT '\-'
DEFINE BAR 7 OF popCard PROMPT 'E\<xit ';
   KEY ALT+X
*** Here is where the POPCARD menu uses the BAR( ) function
*** to pass a bar number to the procedure called choice below.
ON SELECTION POPUP popCard;
   DO choice IN bar_exam WITH BAR( ), POPUP( )
*** The procedure choice uses the gnBar parameter
*** to contain the value passed by the BAR( ) function.
PROCEDURE choice
PARAMETERS gnBar, gcPopup
WAIT WINDOW 'You chose bar #' + LTRIM(STR(gnBar)) + ;
   ' from popup ' + gcPopup NOWAIT
SET SYSMENU TO DEFAULT