program ASMNU2,1.0(100) !ASMNU2 - Demonstration of new menu features (1153+) !----------------------------------------------------------------------- !EDIT HISTORY: ! 1. 21-Jun-09 Created !------------------------------------------------------------------------ ++include ashinc:ashell.def ++include sosfunc:fndec2hex.bsi ! definitions of standard menu items define MID_TOP = 0 ! top level menu bar map1 chk'options(10) ! array of menu check items map2 chk'id,B,2 ! id of menu check item map2 chk'state,B,1 ! 0=unchecked, 1=checked map1 misc map2 i,f,6 map2 sel'mid,f,6 ! menu we are working on map2 status,f map2 mop,b,2 map2 mfile,s,40 map2 state,b,1 map2 exitcode,f map2 dlgid,b,2 START: ? ? "ASMNU2 - Test AUI_MENU functions (5.1.1153+)" ? ! start by adding a Custom > Test1 option to the main menu dlgid = 0 if Fn'AddMenu(MID_TOP,"&Custom",MBST_ENABLE,MBF_SUBMNU,"",dlgid,1005) call MnuErr() ! note we use menu item id 1005 of top level item as parent for submenu item... if Fn'AddMenu(1005,"&Test1",MBST_ENABLE,MBF_KBD,"VK_xF10051",dlgid,10051) call MnuErr() do while exitcode # 1 ? ? "Use Custom > Test1 menu item to launch test, ESC to quit: "; xcall AUI, AUI_EVENTWAIT, 0, 0, exitcode, EVW_NOFOCUS trace.print "$# $T Eventwait exitcode = "+exitcode switch exitcode case -10051 ! menu item id of Custom > Test1 call Menu'Test1() exit endswitch loop ! removing 'Custom' menu... ! note: deleting top menu deletes submenu items ? if Fn'DelMenu(dlgid,MID_TOP,1005) call MnuErr() End Procedure MnuErr() ? ? "AUI_MENU operation error - see status window for details" End Procedure !---------------------------------------------------------------------- ! Procedure: ! Menu'Test1 ! Params: ! Notes: ! Create a dialog, add some menu items to demonstrate capabilities, ! allow user to test them !---------------------------------------------------------------------- Procedure Menu'Test1() define ID_ACTIONS = 20100 ! ID for Action menu item define ID_ACT_GET = 20101 ! ID for Action > Get Menu Check Status item define ID_OPTIONS = 20200 ! ID for Options menu item define ID_OPT_OPT1 = 20210 ! ID for Options > Option 1 menu item define ID_OPT_OPT2 = 20220 ! ID for Options > Option 2 menu item define ID_OPT_OPT3 = 20230 ! ID for Options > Option 3 menu item define ID_OPT_SEP1 = 20240 ! ID for Options (separator 1) define ID_OPT_RAD1 = 20250 ! ID for Options > Radio 1 menu item define ID_OPT_RAD2 = 20260 ! ID for Options > Radio 2 menu item define ID_OPT_RAD3 = 20270 ! ID for Options > Option 3 menu item define ID_OPT_SEP2 = 20280 ! ID for Options > (separator 2) define ID_OPT_DLGBG = 20290 ! ID for Options > Dialog Background (submenu) define ID_OPT_DLGBG_STD = 20291 ! ID for Options > Dialog BG > Standard define ID_OPT_DLGBG_GRN = 20292 ! ID for Options > Dialog BG > Green define ID_OPT_DLGBG_BLU = 20293 ! ID for Options > Dialog BG > Blue map1 locals map2 exitcode,f map2 btnid,b,2 map2 dlgid,b,2 map2 status,f trace.print "$# $T Calling procedure Menu'Test1()..." xcall AUI, AUI_CONTROL, CTLOP_ADD, "dlg1", "Test Menu Dialog", & MBST_ENABLE, MBF_DIALOG, NUL_CMD$, NUL_FUNC$, dlgid, & 5, 5, 10, 50, NUL_FGC, NUL_BGC xcall AUI, AUI_CONTROL, CTLOP_ADD, "txt1", & "This dialog contains /illustrates custom checkmark and radio check menu items." & + " Use the mouse to experiment with them, and the combination of the program source" & + " and the message window to trace the program actions and results.", & MBST_ENABLE, MBF_STATIC, NUL_CMD$, NUL_FUNC$, NUL_CSTATUS, & 1500, 2, 3500, 43, NUL_FGC, NUL_BGC xcall AUI, AUI_CONTROL, CTLOP_ADD, "btn1", "E&xit", & MBST_ENABLE, MBF_BUTTON+MBF_KBD, "VK_ESC", NUL_FUNC$, btnid, & 4000, 18, 5500, 26, NUL_FGC, NUL_BGC ! create some menu items (note that for those menu items which trigger kbd events, ! we're setting the exitcode to match the menu item id by using the virtual key ! syntax "VK_xF#####" where ##### is the menu item id ! Actions drop-down menu call Fn'AddMenu(MID_TOP,"&Actions",MBST_ENABLE,MBF_SUBMNU,"",dlgid,ID_ACTIONS) ! Actions > Get Menu Check Status call Fn'AddMenu(ID_ACTIONS,"&Get Menu Check Status",MBST_ENABLE,MBF_KBD, & "VK_xF"+str(ID_ACT_GET),dlgid,ID_ACT_GET) ! Options drop-down menu call Fn'AddMenu(MID_TOP,"&Options",MBST_ENABLE,MBF_SUBMNU,"",dlgid,ID_OPTIONS) ! Options > Option 1 (2, 3) call Fn'AddMenu(ID_OPTIONS,"Option 1",MBST_ENABLE+MBST_CHECKED,MBF_CHKMNU,"",dlgid,ID_OPT_OPT1) call Fn'AddMenu(ID_OPTIONS,"Option 2",MBST_ENABLE,MBF_CHKMNU,"",dlgid,ID_OPT_OPT2) call Fn'AddMenu(ID_OPTIONS,"Option 3",MBST_ENABLE,MBF_CHKMNU,"",dlgid,ID_OPT_OPT3) ! separator (no particular need to assign an item id to it, but if not, then it needs ! a unique text string to identify it) call Fn'AddMenu(ID_OPTIONS,"Sep1",MBST_ENABLE,MBF_SEP,"",dlgid) ! Options > Radio 1 (2, 3) call Fn'AddMenu(ID_OPTIONS,"Radio 1",MBST_ENABLE+MBST_CHECKED,MBF_RADIOMNU,"",dlgid,ID_OPT_RAD1) call Fn'AddMenu(ID_OPTIONS,"Radio 2",MBST_ENABLE,MBF_RADIOMNU,"",dlgid,ID_OPT_RAD2) call Fn'AddMenu(ID_OPTIONS,"Radio 3",MBST_ENABLE,MBF_RADIOMNU,"",dlgid,ID_OPT_RAD3) ! separator call Fn'AddMenu(ID_OPTIONS,"Sep2",MBST_ENABLE,MBF_SEP,"",dlgid) ! Nest submenu containing radio-check options for changing the color of the dialog ! (Unlike the other check and radio options, these transmit exitcodes for immediate effect) call Fn'AddMenu(ID_OPTIONS,"Dialog Background...",MBST_ENABLE,MBF_SUBMNU, & "",dlgid,ID_OPT_DLGBG) ! Options > Dialog Backgrond > Standard (Green, Blue) call Fn'AddMenu(ID_OPT_DLGBG,"Standard",MBST_ENABLE+MBST_CHECKED,MBF_RADIOMNU+MBF_KBD, & "VK_xF"+str(ID_OPT_DLGBG_STD),dlgid,ID_OPT_DLGBG_STD) call Fn'AddMenu(ID_OPT_DLGBG,"Green",MBST_ENABLE,MBF_RADIOMNU+MBF_KBD, & "VK_xF"+str(ID_OPT_DLGBG_GRN),dlgid,ID_OPT_DLGBG_GRN) call Fn'AddMenu(ID_OPT_DLGBG,"Blue",MBST_ENABLE,MBF_RADIOMNU+MBF_KBD, & "VK_xF"+str(ID_OPT_DLGBG_BLU),dlgid,ID_OPT_DLGBG_BLU) do while exitcode # 1 xcall AUI, AUI_EVENTWAIT, dlgid, btnid, exitcode, EVW_NEXT trace.print "$# $T Eventwait exitcode = "+exitcode switch exitcode case -ID_OPT_DLGBG_STD ! Options > Dialog Background > Standard xcall AUI, AUI_CONTROL, CTLOP_CHG, "dlg1", "Test Menu Dialog", & MBST_ENABLE+MBST_CHANGEX, MBF_DIALOG, NUL_CMD$, NUL_FUNC$, NUL_CSTATUS, & 5, 5, 10, 50, NUL_FGC, NUL_BGC !&h00DDDDDD exit case -ID_OPT_DLGBG_GRN ! Options > Dialog Background > Green xcall AUI, AUI_CONTROL, CTLOP_CHG, "dlg1", "Test Menu Dialog", & MBST_ENABLE+MBST_CHANGEX, MBF_DIALOG, NUL_CMD$, NUL_FUNC$, NUL_CSTATUS, & 5, 5, 10, 50, NUL_FGC, &h0088CC88 exit case -ID_OPT_DLGBG_BLU ! Options > Dialog Background > Blue xcall AUI, AUI_CONTROL, CTLOP_CHG, "dlg1", "Test Menu Dialog", & MBST_ENABLE+MBST_CHANGEX, MBF_DIALOG, NUL_CMD$, NUL_FUNC$, NUL_CSTATUS, & 5, 5, 10, 50, NUL_FGC, &h00CC8888 exit case -ID_ACT_GET: ! Actions > Get Check Status call Fn'CheckMenuState(dlgid,MID_TOP,ID_OPT_OPT1,"Option 1") call Fn'CheckMenuState(dlgid,MID_TOP,ID_OPT_OPT2,"Option 2") call Fn'CheckMenuState(dlgid,MID_TOP,ID_OPT_OPT3,"Option 3") call Fn'CheckMenuState(dlgid,MID_TOP,ID_OPT_RAD1,"Radio 1") call Fn'CheckMenuState(dlgid,MID_TOP,ID_OPT_RAD2,"Radio 2") call Fn'CheckMenuState(dlgid,MID_TOP,ID_OPT_RAD3,"Radio 3") ! Note: we don't really need to query these, since they send us ! exitcodes when clicked (see above) so we could have kept track ! of that last one clicked there. call Fn'CheckMenuState(dlgid,ID_OPT_DLGBG,ID_OPT_DLGBG_STD,"Dlg BG Std") call Fn'CheckMenuState(dlgid,ID_OPT_DLGBG,ID_OPT_DLGBG_GRN,"Dlg BG Green") call Fn'CheckMenuState(dlgid,ID_OPT_DLGBG,ID_OPT_DLGBG_BLU,"Dlg BG Blue") endswitch loop ! if deleting menus individually, do them in reverse order ! (but, deleting dialog will delete the menus, so no need to do it explicitly) ! if Fn'DelMenu(dlgid,MID_TOP,ID_OPTIONS) call MnuErr() ! if Fn'DelMenu(dlgid,MID_TOP,ID_ACTIONS) call MnuErr() xcall AUI, AUI_CONTROL, CTLOP_DEL, "dlg1" trace.print "$# $T Returning from procedure Menu'Test1()" End Function !---------------------------------------------------------------------- ! Function: Fn'AddMenu ! Add new menu item ! Params: ! parentid [num,in] - numeric id of parent menu ! text [str,in] - text of menu item ! state [num,in] - state flags ! type [num,in] - type flags ! cmd [str,in] - command associated with menu ! dlgid [num,in] - dialog id (0=main) ! itemid [num,in] - optional item id for item ! Returns: ! >=0 success !---------------------------------------------------------------------- Function Fn'AddMenu(parentid as b2,text as s32, state as b4, & type as b4, cmd as s200, & dlgid as b2, itemid as b2) as i2 trace.print "$# $T Fn'AddMenu("+parentid+","+text+","+Fn'Dec2Hex$(state)+"," & +Fn'Dec2Hex$(type)+","+cmd+","+dlgid+","+itemid+")..." xcall AUI,AUI_MENU,MNUOP_ADD,parentid,text,state,type,cmd,"",Fn'AddMenu,dlgid,itemid trace.print "$# $T status = "+Fn'AddMenu+" ("+Fn'MenuOpStatus$(MNUOP_ADD,Fn'AddMenu)+")" End Function !---------------------------------------------------------------------- ! Function: Fn'DelMenu ! Delete menu item (by its dialog and item id) ! Params: ! dlgid [num,in] - dialog id ! parentid [num, in] - menu id (parent) ! itemid [num,in] - item id ! Returns: ! >=0 success !---------------------------------------------------------------------- Function Fn'DelMenu(dlgid as b2, parentid as b2, itemid as b2) as i2 trace.print "$# $T Fn'DelMenu("+dlgid+","+itemid+")..." xcall AUI,AUI_MENU,MNUOP_DEL,parentid,"",0,0,"","",Fn'DelMenu,dlgid,itemid trace.print "$# $T status = "+Fn'DelMenu+" ("+Fn'MenuOpStatus$(MNUOP_DEL,Fn'DelMenu)+")" End Function !---------------------------------------------------------------------- ! Function: Fn'CheckMenuState ! Check the state of a checkable (checkbox or radio check) menu item ! Params: ! dlgid [num,in] - dialog id (0 for main window, <0 for context menu) ! parentid [num, in] - parent menuid ! itemid [num,in] - id of menu item ! text [str,in] - optional text describing item (main just for the ! tracing) ! Returns: ! <0 = error (probably item not found) ! else MBST_xxx flags (0=unchecked, 1=disabled, MBST_CHECKED, etc.) ! (Note: must use I4 or F6 since these numbers require 31 bits!) ! Notes: ! In this routine we are identifying the items by the explicit ID ! values we assigned to them when we created the menu items. Another ! method would be to identify them by their text (which might have ! made more sense given that we are passing the text here anyway), ! or by their parent and position within the parent menu. Probably ! an even better method would be to have a single call that retrieved ! all of the checkable menu item status, reducing the round trips to ! just one. (But that hasn't been implemented as of 5.1.1153) !---------------------------------------------------------------------- Function Fn'CheckMenuState(dlgid as b2, parentid as b2, itemid as b2, text as s64) as i4 ! we are identifying the menu item by its dlgid, parent menuid & itemid xcall AUI,AUI_MENU,MNUOP_CHK,parentid,"",0,0,"","",Fn'CheckMenuState,dlgid,itemid trace.print "$# $T Fn'CheckMenuState("+dlgid+","+parentid+","+itemid+","+text+")..." trace.print "$# $T > "+"&h"+Fn'Dec2Hex$(Fn'CheckMenuState) & +" ("+Fn'MenuState$(Fn'CheckMenuState)+")" End Function !---------------------------------------------------------------------- ! Function: Fn'MenuOpStatus$ ! Display description of AUI_MENU operation return code ! Params: ! op [num,in] - operation ! status [signed num,in] - status returned from AUI_MENU ! Returns: ! text of description !---------------------------------------------------------------------- Function Fn'MenuOpStatus$(op as b2, status as i2) as s200 switch status case 0 case 1 Fn'MenuOpStatus$ = "OK" exit case -1 Fn'MenuOpStatus$ = "Operation failed" exit case -2 Fn'MenuOpStatus$ = "Menu not found" exit case -3 Fn'MenuOpStatus$ = "Out of memory" exit case -4 Fn'MenuOpStatus$ = "Too many menus added" exit case -5 Fn'MenuOpStatus$ = "No menu buffer" exit case -6 Fn'MenuOpStatus$ = "Illegal opcode" exit case -7 Fn'MenuOpStatus$ = "Menu already exists" exit case -8 Fn'MenuOpStatus$ = "Illegal menu ID" exit default Fn'MenuOpStatus$ = "Unknown status: "+status exit endswitch End Function !---------------------------------------------------------------------- ! Function: Fn'MenuState$ ! Display description of state returned from MNUOP_CHK call ! Params: ! state [b4,in] - status (state) returned from AUI_MENU MNUOP_CHK ! Returns: ! text of state description !---------------------------------------------------------------------- Function Fn'MenuState$(state as b4) as s200 if (state and MBST_DISABLE) then Fn'MenuState$ = "Disabled" else Fn'MenuState$ = "Enabled" endif if (state and MBST_HILITE) Fn'MenuState$ = Fn'MenuState$ + ",Hilited" endif if (state and MBST_CHECKED) Fn'MenuState$ = Fn'MenuState$ + ",Checked" endif if (state and MBST_DEFAULT) Fn'MenuState$ = Fn'MenuState$ + ",Default" endif End Function ++ifdef NEVER ? "Adding Edit INI menu to custom menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"openf1.bmp::Edit MIAME.INI"+chr(9)+"F5",MBST_ENABLE, & MBF_CMDLIN, "NOTEPAD ..\..\MIAME.INI $","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding Custom menu to top level..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'TOP,"&Custom",MBST_ENABLE, & MBF_SUBMNU,"","",STATUS,0,1005 ? "STATUS = ";STATUS; call SHOW'STATUS ![7] input "Enter 1)File-based interface, 2)Original interface, 3)Popup, 4)Delete popup:",I input "1)File mode, 2)Orig. mode, 3)Def. Popup, 4)Del. popup, 5)Show popup:",I if I<1 or I>5 goto ENDIT on I call SIMPLE'MENU, TRADITIONAL'MENU, & POPUP'MENU'DEF, POPUP'MENU'DELETE, POPUP'MENU'SHOW ! [7] goto START ENDIT: ? "End" End !------------------------------------------------------------------------------- ! Traditional menu interface involves individual XCALLs to add/delete/change ! each menu item. This routine just provides some examples of what is possible. !------------------------------------------------------------------------------- TRADITIONAL'MENU: ! (traditional interface) SEL'MID = MID'FILE ! add to File menu ? "Adding Separator bar to ";MNU'NAME$(SEL'MID);" menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,SEL'MID,"s1",MBST_ENABLE, & MBF_SEP,"","",STATUS ? "STATUS = ";STATUS ? "Adding WINHELP menu to ";MNU'NAME$(SEL'MID);" menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,SEL'MID,"Help on WINHELP",MBST_ENABLE, & MBF_CMDLIN, "WINHELP C:\WINHELP.HLP","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ! [8] ? "Adding Another Separator bar to ";MNU'NAME$(SEL'MID);" menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,SEL'MID,"s2",MBST_ENABLE, & MBF_SEP,"","",STATUS ? "STATUS = ";STATUS ? "Adding WINHELP 'printing' menu to ";MNU'NAME$(SEL'MID);" menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,SEL'MID,"WINHELP key=printing",MBST_ENABLE, & MBF_CMDLIN, "WINHELP -kprinting C:\WINHELP.HLP","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding Custom menu to top level..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'TOP,"&Custom",MBST_ENABLE, & MBF_SUBMNU,"","",STATUS,0,1005 ? "STATUS = ";STATUS; call SHOW'STATUS ! Note that we can add the " $" suffix to the command to make sure ! that this window (A-Shell) does not get suspended while the other ! window is up. ? "Adding Edit INI menu to custom menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"openf1.bmp::Edit MIAME.INI"+chr(9)+"F5",MBST_ENABLE, & MBF_CMDLIN, "NOTEPAD ..\..\MIAME.INI $","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding Calculator menu to custom menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,1005,"Calculator",MBST_ENABLE, & MBF_CMDLIN, "CALC.EXE $","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding Microsabio.com to custom menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"MicroSabio Home Page",MBST_ENABLE, & MBF_SHLEXC, "http://www.microsabio.com","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding SBX:ATECFX to custom menu..."; ! [9] MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"ATECFX",MBST_ENABLE, & MBF_CMDLIN, "SBX:ATECFX,1","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding Checked menu item to custom menu..."; ![10] MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"Checked Item Ctrl+T", & MBST_ENABLE or MBST_CHECKED, MBF_CHKMNU, "","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding SubMenu to custom menu..."; ![11] MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"Options...", & MBST_ENABLE, MBF_SUBMNU, "","",STATUS,0,2000 ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding item to submenu..."; ![11] MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,2000,"Option 1", & MBST_ENABLE or MBST_CHECKED, MBF_RADIOMNU, "","",STATUS,0,2001 ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding item to submenu..."; ![11] MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,2000,"Option 2", & MBST_ENABLE, MBF_RADIOMNU, "","",STATUS,0,2002 ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding Another checked item to custom menu..."; ![10] MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"Checked Item2 Ctrl+1", & MBST_ENABLE, MBF_CHKMNU, "","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? ? "Menus added, try testing them. Then hit RETURN to proceed" STOP ? ? "Disabling 'Calculator' on custom menu..."; MOP = MNUOP_STA ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"Calculator",MBST_DISABLE, & MBF_CMDLIN,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Hiliting checked item n custom menu..."; ![10] MOP = MNUOP_STA ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"Checked Item", & MBST_ENABLE+MBST_HILITE+MBST_CHECKED, MBF_CHKMNU, "","",STATUS ! remove MBST_CHECKED ? "STATUS = ";STATUS; call SHOW'STATUS ? ? "You can check it before hitting RETURN to delete the added menus" STOP ? ? "Unchecking item on custom menu..."; ![10] MOP = MNUOP_STA ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"Checked Item", & MBST_ENABLE, MBF_CHKMNU, "","",STATUS ! remove MBST_CHECKED ? "STATUS = ";STATUS; call SHOW'STATUS ? ? "You can check it before hitting RETURN to delete the added menus" STOP ? ! Note that on delete, the menu is identified by the text ! parameter, which must match exactly (although not case sensitive) ? "Deleting microsabio.com menu from custom menu..."; ! Note menu text not case sensitive MOP = MNUOP_DEL ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"MicroSabio Home Page",0,0,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Deleting Calculator menu from custom menu..."; ! Note menu text not case sensitive MOP = MNUOP_DEL ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"CALCULATOR",0,0,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Deleting Edit MIAME.INI menu from custom menu..."; MOP = MNUOP_DEL ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CUS1,"Edit MIAME.INI",0,0,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Deleting Custom menu from main menu..."; MOP = MNUOP_DEL ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'TOP,"&Custom",0,0,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Deleting WINHELP menu from ";MNU'NAME$(SEL'MID);" menu..."; MOP = MNUOP_DEL ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,SEL'MID,"Help on WINHELP",0,0,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ! [8] ? "Deleting Separator bar #2 from ";MNU'NAME$(SEL'MID);" menu..."; MOP = MNUOP_DEL ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,SEL'MID,"s2",0,0,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Deleting WINHELP 'printing' menu from ";MNU'NAME$(SEL'MID);" menu..."; MOP = MNUOP_DEL ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,SEL'MID,"WINHELP key=printing",0,0,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Deleting Separator bar #1 from ";MNU'NAME$(SEL'MID);" menu..."; MOP = MNUOP_DEL ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,SEL'MID,"s1",0,0,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ! [2] Operations on built-in menus must use zero-relative position instead ! [2] of menu text. Note that separators take up a position. ! [2] Also note that deleting an item causes the ones below it to shift up, ! [2] so you should delete from the bottom up. ! [2] Finally, note that it is possible that the built-in menu layout could ! [2] change, so it may be wise to parameterize any such references to make ! [2] it easy to adjust your app later if necessary. ? ? "Disabling 'Bevelling' on Settings menu..."; MOP = MNUOP_STA ! (for benefit of SHOW'STATUS) ! "Bevelling" is 3rd item on menu (i.e. "2") xcall AUI,AUI_MENU,MOP,MID'SETTINGS,"2",MBST_DISABLE, & MBF_CMDLIN,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Deleting 'Scheduling' on Settings menu..."; MOP = MNUOP_DEL ! (for benefit of SHOW'STATUS) ! "Scheduling" is 1st item on menu (i.e. "0") xcall AUI,AUI_MENU,MOP,MID'SETTINGS,"0",0,0,"","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ! [2] Deleting top level menus is possible also, although not recommended ! ? "Deleting 'Settings' menu..."; ! MOP = MNUOP_DEL ! (for benefit of SHOW'STATUS) ! ! "Settings" is 3rd item on menu (i.e. "2") ! xcall AUI,AUI_MENU,MOP,MID'TOP,"2",0,0,"","",STATUS ! ? "STATUS = ";STATUS; ! call SHOW'STATUS return SHOW'STATUS: ? " "; if STATUS = 0 ? "OK"; :& if MOP=MNUOP_STA and MFILE="" then ? " (was enabled)"; if STATUS = 1 ? "OK"; :& if MOP=MNUOP_STA then ? " (was grayed)"; if STATUS = -1 ? "Operation failed"; if STATUS = -2 ? "Menu not found"; if STATUS = -3 ? "Out of memory"; if STATUS = -4 ? "Too many menus added"; if STATUS = -5 ? "No menu buffer"; if STATUS = -6 ? "Illegal opcode"; if STATUS = -7 ? "Menu already exists"; if STATUS = -8 ? "Illegal menu ID"; if STATUS = 2147483647 ? "Enable/disable failed"; if (STATUS > 1 and STATUS < 2147483647) or STATUS < -8 ? "Other error"; ? return !------------------------------------------------------------------------- ! Simplified menu interface allows you to store the menu information ! in a text file and then add or delete a batch of menus in one step. ! The format of the text file is: ! ;(comment lines start with ;) ! MNU#,TEXT,TYPE,VALUE ! MNU#,TEXT,TYPE,VALUE ! etc. ! Where: ! MNU# is the top level menu # (0=top, 1=File, 2=Edit, 3=Settings...) ! (You can also use "FILE", "EDIT", "SETTINGS", "HELP") ! TEXT is the menu text. For separator bars, specify an arbitrary ! string (e.g. "s1", "s2") to uniquely identify it. ! TYPE is the menu type, from the following: ! "REG" - Registry-associated file. The VALUE will be ! a filespec whose associated application will ! be launched to open it. ! "SUB" - New submenu. (Use with MNU#=0 to add a top level mnu) ! "SEP" - Separator bar ! "KBD" - VALUE contents will be treated as keyboard text ! "CMD" - VALUE contents will be executed as a Windows cmd line ! VALUE - Menu value (see above). May be omitted for TYPE "SEP" !--------------------------------------------------------------------------- SIMPLE'MENU: xcall CCON ! make sure we can abort with ^C print "Enter menu definition file (.mdf) (try sample asmenu.mdf) " input line " or blank for default doc\ashelp.mdf (or ^C to abort): ",MFILE input "Enter 1 to add, 2 to enable/disable, 3 to delete: ",MOP if MOP <= 2 then & input "Enter 0 to enable, 1 to disable: ",STATE xcall AUI,AUI_MENU,MOP,MFILE,STATUS,STATE ? "STATUS = ";STATUS; call SHOW'STATUS ? return !------------------------------------------------------------------------- ! Popup menu definition uses the same syntax as the traditional ! version. Main differences are: ! ! 1. There can be only one context menu for the main window and one ! for each dialog. (The menu is associated with the current dialog ! if there is one; else with the main window.) ! ! 2. The menu ID of the context menu must be negative (typically -1 for ! the main window, -2 for the first dialog, etc.) ! ! 3. To add clipboard operations copy and paste to the popup menu, ! use the MBF_CMDLIN format with the special commands "$COPY" and ! "$PASTE". ($CUT doesn't really apply in this context. ! ! 4. Defining a context menu does not automatically change the cursor to ! an arrow, but you can do that with the TAB(-1,160);chr(32); command ! and TAB(-1,160);chr(48) to set it back to an I-beam. ! ! 5. You can delete the context menu with a single xcall AUI,AUI_MENU ! with OPCODE=3 and TEXT="*". !--------------------------------------------------------------------------- POPUP'MENU'DEF: ? "Creating context menu for main window..." ! Note that we can add the " $" suffix to the command to make sure ! that this window (A-Shell) does not get suspended while the other ! window is up. ? "Adding Edit INI menu to context menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CONTEXT,"Edit MIAME.INI",MBST_ENABLE, & MBF_CMDLIN, "NOTEPAD ..\..\MIAME.INI $","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding Calculator to context menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CONTEXT,"Calculator",MBST_ENABLE, & MBF_CMDLIN, "CALC.EXE $","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding Separator bar..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CONTEXT,"s1",MBST_ENABLE, & MBF_SEP,"","",STATUS ? "STATUS = ";STATUS ? "Adding Microsabio.com to context menu..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CONTEXT,"MicroSabio Home Page",MBST_ENABLE, & MBF_SHLEXC, "http://www.microsabio.com","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS ? "Adding another Separator bar..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CONTEXT,"s2",MBST_ENABLE, & MBF_SEP,"","",STATUS ? "STATUS = ";STATUS ? "Adding Clipboard Copy..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CONTEXT,"Copy",MBST_ENABLE, & MBF_CMDLIN,"$COPY","",STATUS ? "STATUS = ";STATUS ? "Adding Clipboard Paste..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CONTEXT,"Paste",MBST_ENABLE, & MBF_CMDLIN,"$PASTE","",STATUS ? "STATUS = ";STATUS ? "Adding Hello World..."; MOP = MNUOP_ADD ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CONTEXT,"Hello World",MBST_ENABLE, & MBF_KBD,"Hello World","",STATUS ? "STATUS = ";STATUS ? "Setting cursor to arrow..." ? tab(-1,160);chr(32) ? ? "Context menu created; right click to test." STOP ? "Disabling Calculator item on context menu..."; MOP = MNUOP_STA ! (for benefit of SHOW'STATUS) xcall AUI,AUI_MENU,MOP,MID'CONTEXT,"Calculator",MBST_DISABLE, & MBF_CMDLIN, "CALC.EXE $","",STATUS ? "STATUS = ";STATUS; call SHOW'STATUS return !------------------------------------------------------------------------- ! Delete context menu !------------------------------------------------------------------------- POPUP'MENU'DELETE: ? "Deleting context menu..."; MOP = MNUOP_DEL xcall AUI,AUI_MENU,MOP,MID'CONTEXT,"*",MBST_ENABLE, & MBF_CMDLIN,"","",STATUS ? "STATUS = ";STATUS ? "Setting cursor back to I-Beam..." ? tab(-1,160);chr(48) return !------------------------------------------------------------------------- ! Show context menu under program control ! [7] !------------------------------------------------------------------------- POPUP'MENU'SHOW: xcall AUI,AUI_MENU,4,MID'CONTEXT,"",1,50,"","",STATUS return !defstruct ST_MENU_ITEM ! [11] ! map2 text,s,32 ! map2 cmd,s,50 ! map2 state,b,4 ! map2 menuid,b,2 ! map2 itemid,b,2 !endstruct ++endif