Microsoft KB Archive/135517

= How to Attach a Menu to a Form =

Article ID: 135517

Article Last Modified on 8/25/1999

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q135517



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
 Create a form named Form1.  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\  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  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: KB135517

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.