MENU.BAS Using the procedures in MENU.BAS is straightforward. In most cases, the demonstration program UIDEMO.BAS provides enough information for a BASIC programmer of some experience to get started. However, a few notes of introduction are in order. When you use the procedures in MENU.BAS, you must provide the following global array declarations in your program, in the order shown. COMMON SHARED -uitools-GloMenu AS MenuMiscType COMMON SHARED -uitools-GloTitle() AS MenuTitleType COMMON SHARED -uitools-GloItem() AS MenuItemType DIM GloTitle(MAXMENU) AS MenuTitleType DIM GloItem(MAXMENU, MAXITEM) AS MenuItemType The order is important because the block defined by COMMON in the Quick library must agree with the block defined by COMMON in the programming environment. These global arrays are used to store information about the menus you define. As previously mentioned, the menus in the User Interface toolbox work like those in the QBX programming environment. Menu titles are displayed on a menu bar that extends across the top of the screen in row 1. Associated with each menu are one or more menu items. From the programmer's standpoint, menus are numbered from left to right, beginning at 1. Menu items -that is, those choices associated with each menu - are numbered from top to bottom, also beginning at 1. For any given menu, menu item 0 is always the menu title. The MenuColor procedure lets you select the color scheme for your menus. A single MenuSet statement is all that is required to set up each menu title on the menu bar or each menu item associated with a menu. Menus can be selected with the mouse - by pointing and clicking - or with the keyboard, by pressing the Alt key and the highlighted letter in the desired menu title. When a menu is selected, the choices associated with that menu will pull down, or drop, from the menu bar so that you can see the choices available. When a pull-down menu is displayed, menu items can be chosen by pointing and clicking with the mouse, or pressing the highlighted key associated with that choice. The key combinations used in the latter selection technique are called access keys. Access keys consist of a series of menu-item-selection keystrokes; each series begins by pressing the Alt key. You also can set up shortcut keys to use in lieu of the mouse or the regular access keys. Shortcut keys can use any character or extended character, except those that use the Alt key. For example, you can use Ctrl+X, Ctrl+F10, or simply F3). To enable a shortcut key, use a ShortCutKeySet statement to identify the menu and menu item with the definition of the short-cut key. Before actually building your menus, you need to initialize global arrays to speed up menu response. Use the MenuInit procedure to initialize the arrays you declared and initialize the mouse. The following code fragment illustrates how to put together a short menu with one title, two item choices and a means of exiting the menu. MenuInit ' Initialize everything, including the mouse. MenuSet 1,0,1,"Menu Title",1 ' Set up menu title. MenuSet 1,1,1,"Selection 1 F1",11 ' Set up first selection. MenuSet 1,2,1,"Selection 2 F2",11 ' Last parameter determines ' highlight. MenuSet 1,3,1,"-",1 ' Make a line across the menu. MenuSet 1,4,1,"Exit Ctrl-X",2 ' Set up way to get out. ShortCutKeySet 1,1,CHR$(0)+CHR$(59) ' Set F1 as shortcut key for 1. ShortCutKeySet 1,2,CHR$(0)+CHR$(60) ShortCutKeySet 1,4,CHR$(24) ' Set Ctrl-X for Exit. MenuColor 14,1,12,8,14,3,12 ' Specify color scheme MenuPreProcess ' Do all necessary calculations. MenuShow ' Display the menu. MouseShow ' Make mouse cursor visible. Notice that the menu title is described as menu 1, item 0. Item 0 means that the MenuSet statement specifies a menu title, not a menu item. Numbers from 1 through 4 are the remaining selections. Item 3 is special. It's not really a selection item. The hyphen character (-) causes a bar to be placed across the pull-down menu. It is useful for breaking up functional groupings of menu selections. You can't select it, so you should remember to use a SELECT CASE statement that excludes that item number when processing the selections. See the demonstration program UIDEMO.BAS for a working example. Also notice that within the text for Selection 1, F1 is shown to the right. F1 is the shortcut key for Selection 1 that is programmed using the first ShortCutKeySet statement. The extended keyboard code for the F1 key is CHR$(0) + CHR$(59). Use MenuColor to set up the colors for your menus, the highlighted colors to use when an item is selected, and the highlighted characters to use when choosing a menu item from the keyboard. MenuPreProcess performs the necessary calculations and builds indexes that help speed up menu execution. MenuShow actually displays the menu bar on the screen. The three-dimensional shadow and other programming chores are handled for you automatically. Once the menu bar is displayed, the call to MouseShow makes the mouse cursor visible. After you've displayed your menus, you want to be able to have the program translate the available choices into action. Processing menu selections is also very straightforward. The MenuInkey$ procedure within a WHILE...WEND control-flow structure serves well to poll user input. The following code fragment illustrates how to process user input and translate a user's choice to a desired action. Finished = FALSE WHILE NOT Finished kbd$ = MenuInkey$ ' Monitor all user input. SELECT CASE kbd$ ' See what the user entered. CASE "menu" ' If kbd$ = "menu". menu = MenuCheck(0) ' Get menu number. item = MenuCheck(1) ' Get item number. GOSUB HandleMenuEvent ' Handle selection. CASE ELSE . . ' If kbd$ = anything else. . END SELECT WEND HandleMenuEvent. SELECT CASE menu CASE 1 ' Handles Menu 1 . SELECT CASE item CASE 1 Selection1Routine ' Handle selection 1. CASE 2 Selection2Routine ' Handle selection 2. CASE 4 Finished = TRUE ' Handle Exit. END SELECT END SELECT RETURN The code shown above processes keyboard input and mouse input with MenuInkey$. If you wanted to preclude any keyboard input, you could use MenuEvent instead of MenuInkey$, as follows. WHILE NOT Finished MenuEvent ' Monitor menu events only. IF MenuCheck(2) THEN menu = MenuCheck(0) ' Get menu number. item = MenuCheck(1) ' Get item number. GOSUB HandleMenuEvent ' Determine which item. END IF . ' What to do if MenuCheck(2) . ' hasn't changed. . WEND The preceding information is intended to give you an overview of how the menus work. With this information and the detailed information provided for each procedure, you should be able to incorporate menus into your BASIC applications. Be sure to see the example code in UIDEMO.BAS that demonstrates how most of the procedures are used. A description of each procedure that comprises MENU.BAS is next.