Share via


DEFINE MENU Command

Creates a menu bar.

DEFINE MENU MenuBarName [BAR [AT LINE nRow]]
   [IN [WINDOW] WindowName | IN SCREEN] [FONT cFontName [, nFontSize]]
   [STYLE cFontStyle] [KEY KeyLabel] [MARK cMarkCharacter]
   [MESSAGE cMessageText] [NOMARGIN] 
   [COLOR SCHEME nSchemeNumber | COLOR ColorPairList]

Parameters

  • MenuBarName
    Specifies the name of the menu bar to create. The menu bar name allows you to reference the menu bar in other commands and functions.

  • BAR [AT LINE nRow]
    Creates a menu bar that behaves like the Visual FoxPro system menu bar. The menu bar has these characteristics:

    • A horizontal menu bar one line high is drawn across the width of the main Visual FoxPro window or the user-defined window it is placed in.
    • The placement of the menu titles on the menu bar is handled automatically.
    • If the size or number of menu titles you define exceeds the size of the screen or a window in which the menu bar is placed**,** the menu bar scrolls.

    The row number is specified with nRow.

  • IN [WINDOW] WindowName
    Places a menu bar in a user-defined window. Specify the name of the window in which you want to place the menu bar with WindowName. If you omit IN WINDOW, the menu bar is placed in the main Visual FoxPro window by default unless there is an active user-defined window. If there is an active user-defined window, the menu bar is placed in the active window. This clause is supported only in top-level forms which can be set with ShowWindow=2 or Desktop=.T.

  • IN SCREEN
    Explicitly places the menu bar in the main Visual FoxPro window.

  • FONT cFontName [, nFontSize]
    Specifies a default font for all menu titles in the menu bar. You can override the default font for an individual menu title by including the FONT clause in DEFINE PAD.

    cFontName specifies the name of the font, and nFontSize specifies the point size. For example, the following command creates a menu bar with menu titles in 12-point Courier font:

    DEFINE MENU mnuExample FONT 'Courier', 12
    

    If the font you specify is not available, a font with similar font characteristics is substituted. If you include the FONT clause but omit the point size nFontSize, a 10-point font is used.

    The FONT clause is ignored for menu titles added to the Visual FoxPro system menu _MSYSMENU. Note that the Menu Designer uses the Visual FoxPro system menu.

  • STYLE cFontStyle
    Specifies a default font style for all the menu titles in the menu bar. You can override the default style for individual menu titles by including the STYLE clause in DEFINE PAD.

    If you omit the STYLE clause, or if the font style you specify is not available, the Normal font style is used.

    The font styles you can specify with cFontStyle are as follows:

    Character Font style
    B Bold
    I Italic
    N Normal
    Q Opaque
    - Strikeout
    T Transparent
    U Underline

    You can include more than one character to specify a combination of font styles. For example, the following command specifies Bold Italic:

    DEFINE MENU mnuExample STYLE 'BI'
    

    The STYLE clause is ignored for menu titles added to the Visual FoxPro system menu _MSYSMENU. The Menu Designer uses the Visual FoxPro system menu.

  • KEY KeyLabel
    Specifies the key or key combination used to activate the menu bar. For a list of available keys and key combinations and their key label names, see ON KEY LABEL.

    Including the KEY clause is equivalent to issuing the following command:

    ON KEY LABEL KeyLabel ACTIVATE MENU MenuName
    

    Note   If a keyboard macro is already defined with the same key label, the keyboard macro takes precedence, and the menu bar cannot be activated with the specified key or key combination.

  • MARK cMarkCharacter
    Specifies a mark character that appears to the left of the menu titles on the menu bar. MARK can be included to change the default mark character to a character specified with cMarkCharacter. If cMarkCharacter includes more than one character, only the first character is used as the mark character.

    The default mark character is a check. The MARK clause is ignored and the default mark character is used if the menu bar is the Visual FoxPro system menu. Also, the MARK clause is ignored if FoxFont isn't the font for the main Visual FoxPro window or the user-defined window in which the menu bar is placed.

    Note   Specifying a mark character doesn't mark the menu names on a menu bar. Use SET MARK OF to mark the menu titles on a menu bar with the character you specify.

    Mark characters specified with DEFINE PAD take precedence over mark characters specified with the MARK clause in DEFINE MENU. SET MARK OF is used to toggle mark characters on or off, and can also be used to specify a mark character for an individual menu item or for all menu items.

  • MESSAGE cMessageText
    Displays a message when the user selects a menu title. The message is placed in the graphical status bar. If the graphical status bar is turned off with SET STATUS BAR OFF, the message is centered on the last line of the main Visual FoxPro window.

  • NOMARGIN
    Removes the spaces that are placed to the left and right of each menu name by default.

  • COLOR SCHEME nSchemeNumber
    Specifies the colors for an individual menu bar.

  • COLOR ColorPairList
    Specifies the colors for an individual menu bar. By default, the colors of menu items are determined by color scheme 2 of the current color set.

Remarks

Use DEFINE MENU to create the menu bar for your application's menu system. Use DEFINE PAD to create each of the menu titles (pads) on the menu bar. Use ON PAD ... ACTIVATE to specify which menu is displayed under each menu title. Use DEFINE POPUP to create the menus under each menu title. Use ACTIVATE MENU to activate the entire menu system.

If you use the Menu Designer to create your menu, you may not have to use these commands at all. The Menu Designer automatically creates the commands for your menu. The Menu Designer uses the Visual FoxPro system menu, which you can then modify by adding your own menu items.

For more information on creating menus, see Menu System Creation.

Example

The following example uses DEFINE MENU to create a user-defined menu system. The current system menu bar is first saved to memory with SET SYSMENU SAVE, and then the system menu titles are cleared with SET SYSMENU TO.

DEFINE MENU creates the menu bar, and two menu titles are created with DEFINE PAD. DEFINE POPUP creates a menu for each menu title. DEFINE BAR creates items on each of the menus. When a menu title is chosen, ON PAD uses ACTIVATE POPUP to activate the corresponding menu. ACTIVATE MENU displays and activates the menu bar.

When an item is chosen from a menu, the CHOICE procedure is executed. CHOICE displays the name of the chosen item and the name of the menu containing the item.

** Name this program DEFIMENU.PRG ** CLEAR SET SYSMENU SAVE SET SYSMENU TO ON KEY LABEL ESC KEYBOARD CHR(13) DEFINE MENU example BAR AT LINE 1 DEFINE PAD convpad OF example PROMPT '<Conversions' COLOR SCHEME 3 ; KEY ALT+C, '' DEFINE PAD cardpad OF example PROMPT 'Card <Info' COLOR SCHEME 3 ; KEY ALT+I, '' ON PAD convpad OF example ACTIVATE POPUP conversion ON PAD cardpad OF example ACTIVATE POPUP cardinfo DEFINE POPUP conversion MARGIN RELATIVE COLOR SCHEME 4 DEFINE BAR 1 OF conversion PROMPT 'Ar<ea' ; KEY CTRL+E, '^E' DEFINE BAR 2 OF conversion PROMPT '<Length' ; KEY CTRL+L, '^L' DEFINE BAR 3 OF conversion PROMPT 'Ma<ss' ; KEY CTRL+S, '^S' DEFINE BAR 4 OF conversion PROMPT 'Spee<d' ; KEY CTRL+D, '^D' DEFINE BAR 5 OF conversion PROMPT '<Temperature' ; KEY CTRL+T, '^T' DEFINE BAR 6 OF conversion PROMPT 'T<ime' ; KEY CTRL+I, '^I' DEFINE BAR 7 OF conversion PROMPT 'Volu<me' ; KEY CTRL+M, '^M' ON SELECTION POPUP conversion DO choice IN defimenu WITH PROMPT( ), POPUP( ) DEFINE POPUP cardinfo MARGIN RELATIVE COLOR SCHEME 4 DEFINE BAR 1 OF cardinfo PROMPT '<View Charges' ; KEY ALT+V, '' DEFINE BAR 2 OF cardinfo PROMPT 'View <Payments' ; KEY ALT+P, '' DEFINE BAR 3 OF cardinfo PROMPT 'Vie<w Users' ; KEY ALT+W, '' DEFINE BAR 4 OF cardinfo PROMPT '-' DEFINE BAR 5 OF cardinfo PROMPT '<Charges ' ON SELECTION POPUP cardinfo; DO choice IN defimenu WITH PROMPT( ), POPUP( )

ACTIVATE MENU example
DEACTIVATE MENU example
RELEASE MENU example EXTENDED
SET SYSMENU TO DEFAULT
ON KEY LABEL ESC
PROCEDURE choice
PARAMETERS mprompt, mpopup
WAIT WINDOW 'You chose ' + mprompt + ;
    ' from popup ' + mpopup NOWAIT

See Also

ACTIVATE MENU | CNTPAD( ) | CREATE MENU | DEACTIVATE MENU | DEFINE PAD | GETPAD( ) | HIDE MENU | MRKPAD( ) | ON PAD | ON SELECTION PAD | PRMPAD( ) | RELEASE MENUS | RELEASE PAD | SET MARK OF | SET SYSMENU | SHOW MENU