KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q135517: How to Attach a Menu to a Form

Article: Q135517
Product(s): Microsoft FoxPro
Version(s): 
Operating System(s): 
Keyword(s): 
Last Modified: 25-AUG-1999

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual FoxPro for Windows, version 3.0 
-------------------------------------------------------------------------------

SUMMARY
=======

This article shows by example how to add a menu to a Visual FoxPro form so that
the menu appears on the form rather than in the default position across the top
of the screen.

MORE INFORMATION
================

In Visual FoxPro, menus are not objects that can be instantiated (created) on or
in a form. Nevertheless, you can add a menu directly to the form so that it
appears on the form underneath the title bar rather than in the default system
menu position across the top of the screen. To do this, use the DEFINE MENU
command as shown in the following example.

Step-by-Step Example
--------------------

1. Create a form named Form1.

2. In the Activate event procedure for the form, include the following code to
  define the menu bar, and menu lists. Include the ACTIVATE MENU command.

     CLEAR
     SET SYSMENU SAVE
     SET SYSMENU TO
     ON KEY LABEL ESC KEYBOARD CHR(13)
     DEFINE MENU example BAR in window FORM1
     DEFINE PAD convpad OF example PROMPT '\<Conversions' COLOR SCHEME 3;
        KEY ALT+C, ''
     ON PAD convpad OF example ACTIVATE POPUP conversion
     DEFINE POPUP conversion MARGIN RELATIVE SHADOW 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()
     ACTIVATE MENU example nowait

3. In the Unload event procedure of the form, include the following code to
  deactivate the menu and restore the default system menu.

     DEACTIVATE MENU example
     RELEASE MENU example EXTENDED
     SET SYSMENU TO DEFAULT
     ON KEY LABEL ESC

4. Save and run the form. A menu bar with a single option (Conversion) will
  appear just below the title of the form. The default system menu bar will
  disappear. When the form is released, the defined menu will also be released
  and the default system menu bar restored.

NOTE: It is possible to use code generated by the Menu Designer, but you would
need to edit the generated code before using it. The generated menu is not a new
menu; it is still the system menu. You must alter the code to specifically name
and define the menu, to activate the menu, and to save and clear the system
menu. It is easier to generate the menu, copy and paste the generated menu code
into the Activate event procedure code, and then modify the code there.

Any procedures executed by individual menu items are best included in the
existing procedure files for the project or database.

Additional query words: VFoxWin

======================================================================
Keywords          :  
Technology        : kbVFPsearch kbAudDeveloper kbVFP300

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.