下面的示例使用 bar( ) 将一个菜单项的编号传递给一个过程。用set sysmenu save 命令将当前系统菜单栏保存到内存中,然后用 set sysmenu to 命令删除所有系统菜单标题。define pad 命令创建了两个菜单标题,define popup 为每一个菜单标题创建一个菜单,define bar 在每一个菜单上创建菜单项。当选择菜单标题时,on pad 使用 activate popup 命令激活相应菜单。当从菜单中选择一个菜单项时,on selection popup 使用 bar( ) 和 popup( ) 把菜单项编号和菜单标题传递给 choice 过程,choice 过程将显示所选菜单项的编号及其所属的菜单的名称。若选择 card info 菜单的 exit 项,原来的 visual foxpro 系统菜单将由
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 shadow 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 shadow 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
endif