IMPORT

Define Menu, Define Pad, Define Popup, Define Bar, Release Menus, Release Pad, Release Popups, Release Bar

These commands create and destroy the components of a Windows-style menu. See Menus for an explanation of the various components.

Because the Menu Designer generates the DEFINE commands for you and the RELEASEs aren't needed when you're dealing with the system menu bar, you'll rarely write these commands yourself. This is somewhat less true in VFP 7, where new capabilities for menu bars may lead you to write some menu handling code yourself.

Usage

DEFINE MENU MenuBarName         [ BAR [ AT LINE nRow ] ]         [ IN [ WINDOW ] ContainingWindow | IN SCREEN ]         [ FONT cFontName [, nFontSize ] ] [ STYLE cStyleCodes ]         [ KEY KeyLabel ] [ MARK cMarkCharacter ]         [ MESSAGE cMessageText ] [ NOMARGIN ]         [ COLOR SCHEME nScheme | COLOR ColorPairList ] RELEASE MENUS [ MenuBarList [ EXTENDED ] ]   DEFINE PAD PadName1 OF MenuBarName PROMPT cPadText         [ AT nRow, nColumn ]         [ BEFORE PadName2 | AFTER PadName3 ]         [ NEGOTIATE PositionInVFP [, PositionInActiveDoc ] ]         [ FONT cFontName [, nFontSize ] ] [ STYLE cStyleCodes ]         [ KEY KeyLabel [, cKeyText ] ] [ MARK cMarkCharacter ]         [ SKIP [ FOR lExpression ] ] [ MESSAGE cMessageText ]         [ COLOR SCHEME nScheme | COLOR ColorPairList ] RELEASE PAD PadName | ALL OF MenuBarName    DEFINE POPUP PopupName                  [ FROM nTop, nLeft ] [ TO nBottom, nRight ]         [ IN [ WINDOW ] ContainingWindow | IN SCREEN ]         [ FONT cFontName [, nFontSize ] ] [ STYLE cStyleCodes ]         [ PROMPT FIELD FieldName           | PROMPT FILES [ LIKE FileSkeleton ]               | PROMPT STRUCTURE ]         [ TITLE cMenuTitleText ] [ FOOTER cFooterText ]          [ KEY KeyLabel ] [ MESSAGE cMessageText ]         [ MARGIN ] [ MARK cMarkCharacter ]         [ MOVER ] [ MULTISELECT ] [ SCROLL ]         [ SHORTCUT ]         [ RELATIVE ] [ SHADOW ]         [ COLOR SCHEME nScheme | COLOR ColorPairList ] RELEASE POPUPS [ PopupList [ EXTENDED ] ]    DEFINE BAR nBarNumber1 | SystemItemName OF PopupName          PROMPT cBarText         [ PICTURE cPictureFile | PICTRES nSystemBar ]         [ BEFORE nBarNumber2 | AFTER nBarNumber3 ]         [ FONT cFontName [, nFontSize ] ] [ STYLE cStyleCodes ]         [ KEY KeyLabel [, cKeyText ] ] [ MARK cMarkCharacter ]         [ MESSAGE cMessageText ] [ SKIP [ FOR lExpression ] ]         [ COLOR SCHEME nScheme | COLOR ColorPairList ]         [ MRU ] [ INVERT ] RELEASE BAR nBarNumber | SystemItemName | ALL OF PopupName
The DEFINE commands create the objects and leave them in memory. You need an ACTIVATE command or SYSMENU set appropriately to actually use these things. The RELEASE commands remove the definitions from memory.

There are a few things here that are different from FoxPro 2.x, as well as a few that are just plain confusing. Let's take a look.

The FONT and STYLE clauses at each level were added in VFP 3. These clauses let you decide what font to use when you're not working with the system menu. The system menu picks up its font settings from the Registry and ignores any fonts you specify.

Like so many other menu components, fonts propagate from container to contained item. That is, the font you specify for a menu is used for the pads of that menu, unless they include the FONT clause. The font you specify for a popup applies to all bars in that popup that don't have their own font definition.

These clauses give you the ability to create menus as ugly as some of the flyers we receive for social events. Just because you can use lots of different fonts doesn't mean you should.

We ranted in the original Hacker's Guide about the inability to set fonts for the system menu. Since then, however, we've come to see the user-interface light and realized that menus really should be based on system-wide settings and that coding specific fonts and sizes into your application's menus is likely to annoy your users.

The MARK clause is ignored. No matter what you specify, you get the checkmark character. The SHADOW clause is another that appears to be ignored, although GENMENU includes it for popups other than shortcut menus you define in the Menu Designer.

DEFINE PAD's NEGOTIATE clause controls what happens to a pad when your application works with another application. How the pad behaves for OLE in-place editing is dictated by the PositionInVFP keyword; how it behaves in an active document is determined by the PositionInActiveDoc. The choices are NONE, LEFT, RIGHT and MIDDLE. NONE means the pad doesn't appear in that case. The exact meaning of MIDDLE seems to vary depending on which application is taking over. For active documents, RIGHT means "put the item on the Help menu." Weird behavior, but it is documented that way.

The PROMPT clause of DEFINE POPUP lets you create a popup without having to define individual bars. You can automatically fill it with a list of files, the fields of a table, or, the most useful, the value of an expression for each record in a table. These popups are pretty restricted in what else they can do—no multiselect and no mover bars are the most serious restrictions.

The SHORTCUT keyword of DEFINE POPUP was added in VFP 5 to make it easier to create context (or shortcut) menus. When you add the SHORTCUT keyword, the generated popup has the substantial 3-D look of Windows' context menus. Without it, the popup is a pretty sad-looking thing.

Beginning in VFP 7, you can specify an icon to appear on a menu bar. There are two, mutually exclusive, ways to do it. Use the PICTURE clause to specify a picture file. You can specify pretty much any picture file, but if it's too big, it's not going to look as you expect. The alternative approach is to take advantage of the icons already included in the VFP system menu. Use PICTRES and follow it with the constant for any VFP menu item, found in the Help file under "System menu names." (The names of the VFP menu bars are really just constants for large negative numbers.) The DEFINE POPUP for the menu containing the bars must have the MARGIN clause for the pictures to show up—again, the Menu Designer takes care of this for you.

Menu bars in VFP 7 have two other new capabilities. The MRU clause indicates that the bar should display the downward-pointing chevron used by other Windows applications (and Windows itself) to indicate that more items are available. Unlike ordinary menu items, holding the mouse over an MRU item for more than a brief moment fires the code associated with it. That code can do whatever you want—most often, it will expand the menu options, just as in Windows and Office. While the MRU item doesn't have to be the last item on a given popup, you probably want it to be.

The other clause new to VFP 7 is INVERT, which makes a bar look as if it's set back from the other items on the menu popup. Bars with the INVERT characteristic usually have a background paler than those without it. (The exact appearance depends on the Windows color scheme.) A typical use of INVERT is to distinguish the items added after the user chooses the MRU item from the items always on the menu.

The Menu Designer supports the PICTURE and PICTRES clauses, but there's no direct way to add MRU or INVERT clauses. However, as with other clauses not supported in the Menu Designer, you can specify them in the Skip For condition by putting them after the desired condition. If no Skip For clause is needed, use .F. for the condition, like this:

.F. MRU 
In VFP 7, GenMenu.PRG removes any SKIP FOR .F. clauses from DEFINE BAR commands (leaving any following clauses), so there's no longer a performance penalty for tricking the designer in this way.

Some of the other common clauses are discussed under Menus.

Example

DEFINE MENU MyMenu FONT "Arial",14 STYLE "I" DEFINE PAD MyFirst OF MyMenu PROMPT "First" DEFINE PAD MySecond OF MyMenu PROMPT "Second"   DEFINE POPUP MyPop1  DEFINE BAR 1 OF MyPop1 PROMPT "Item 1" DEFINE BAR 2 OF MyPop1 PROMPT "Item 2"   DEFINE POPUP MyPop2 MARGIN DEFINE BAR 1 OF MyPop2 PROMPT "Other 1" FONT "Courier New",12 DEFINE BAR 2 OF MyPop2 PROMPT "Other 2" ;    PICTURE HOME() + "FFC\GRAPHICS\HYPERLINK.ICO" DEFINE BAR 3 OF MyPop2 PROMPT "Other 3" PICTRES _mtl_wzrds   ON PAD MyFirst OF MyMenu ACTIVATE POPUP MyPop1 ON PAD MySecond OF MyMenu ACTIVATE POPUP MyPop2   ON SELECTION BAR 1 OF MyPop1 ?"Item 1 chosen" ON SELECTION BAR 2 OF MyPop1 ?"Item 2 chosen" ON SELECTION POPUP MyPop2 ?"Item from Popup2" ON SELECTION BAR 3 OF MyPop2 ?"But I'm different"   ACTIVATE MENU MyMenu

See Also

Activate Menu, Activate Popup, Deactivate Menu, Deactivate Popup, Menus, On Bar, On Pad, On Selection Bar, On Selection Menu, On Selection Pad, On Selection Popup


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net