How to Easily Give a Screen Its Own User-Defined Menu

ID: Q123157

2.50x 2.6x | 2.50x 2.6x | 2.5x 2.60a

WINDOWS    | MS-DOS     | MACINTOSH

The information in this article applies to:

SUMMARY

This article shows by example how to create a screen and give it an active menu while also keeping the main system menu active. For example, the Trace window has its own menu and is active while the main FoxPro system menu is active.

MORE INFORMATION

For information about how to attach a menu to a Visual FoxPro 3.0 form, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q135517
   TITLE     : How to Attach a Menu to a Form

FoxPro 2.x Instructions

You could create a menu to be included with a screen by hand coding the menu. But it is easier to use FoxPro's menu generator to generate menu code. Then you can identify and copy the appropriate sections of generated code (.MPR), and paste these sections into the screen code (.SCX).

Step-by-Step Example

1. Create a screen file, and give the screen a name in the screen layout.

2. Create a menu to go with the screen by using the menu builder. Then

   generate it by using the menu generator.

3. Create a #SECTION2 in the setup code of the screen. On the last line of
   the Setup snippet of your screen, type in the following:

   #SECTION2

4. Copy the "Menu Definitions" section of the generated menu file (the .MPR
   file) to the line below the #SECTION2 section created in the previous
   step. But do not copy any of the menu procedure code; this code will be
   placed in the cleanup code of the screen.

5. Copy the menu procedures labeled on the selection bar to the screen
   cleanup and procedures section of the screen. From this point on all
   reference in this article to menu code will refer to the menu code
   copied to the screen (.SCX) file.

6. In the menu code, replace the first line (SET SYSMENU TO) with "define
   menu <menu name> in window <screen name>" where menu name is any name
   you want and screen name is the name you gave the screen in the screen
   layout dialog box.

   For example, if the menu generator generated the following first two
   lines of code:

      SET SYSMENU TO
      SET SYSMENU AUTOMATIC

   Replace the above lines with the following;

      SET SYSMENU AUTOMATIC
      DEFINE MENU mymenu IN WINDOW test

7. In the menu code, replace all occurrences of _MSYSMENU with your menu
   name. For example, one line of the menu code might look like this:

      DEFINE PAD _qt00iyosr OF _MSYSMENU PROMPT "file" COLOR SCHEME 3

   Change the _MSYSMENU to your menu name (for example, mymenu):

      DEFINE PAD _qt00iyosr OF mymenu PROMPT "file" COLOR SCHEME 3

8. Change the following lines:

      ON SELECTION BAR 1 OF file ;
                   DO _qt00iyovc ;
                   IN LOCFILE(...

   To this:

      ON SELECTION BAR 1 OF file ;
                   DO _qt00iyovc

9. Add the following line to the ON WINDOW ACTIVATE clause of the screen
   code:

   ACTIVATE MENU mymenu NOWAIT

10. Generate the screen code, and execute the .SPR file.

NOTE: The menu created in the above example isn't a true system menu, so the menu does not look or behave exactly like a system menu. For example, if you select a menu pad you must execute "DEACTIVATE POPUP padname" to close up the pad. Clicking with the mouse off the menu pad will not deactivate the menu.

Additional reference words: FoxWin FoxDos FoxMac 2.50 2.50a 2.50b 2.50c 2.60 2.60a KBCategory: KBSubcategory: FxtoolMBuilder

Keywords          : kbcode FxtoolMBuilder 
Version           : 2.50x 2.6x | 2.50x 2.6x | 2.5x 2
Platform          : MACINTOSH MS-DOS WINDOWS

Last Reviewed: May 22, 1998