Microsoft KB Archive/157160

= How To Provide Edit Menu Functions in a Top-Level Form =

Article ID: 157160

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q157160



SUMMARY
This article describes how you can provide Edit menu functionality, such as Cut, Copy, and Paste, to a Top-Level form without actually using a visual menu bar and pad on the form.

If you do not include any of the System menu items, the Top-Level Form loses the functionality of the System menu because it runs as a "separate" application outside of the Visual FoxPro environment.



MORE INFORMATION
Sometimes, you may want to create an application that does not require a main menu, but you want to have the ability to cut, copy, or paste in a text box or edit box field from within the form. In previous versions of the FoxPro, you need to include the Edit menu in your application. However, this is no longer necessary in Visual FoxPro 5.0 or later.

The following example shows how you can create a form that can invoke Cut, Copy, or Paste functionality without having the Edit menu visible.

 Create a Quick Menu. Delete all the menu pads and bars that you don't need and leave only Cut, Copy and Paste. On the View menu, click General Options. Select the Top-Level Form check box in the General Options dialog box. Generate the menu and save it as Sdieditmenu.mnx. Create a form and name it Sdieditform1.scx. Set the ShowWindow property for the form to "2 - As Top-Level Form" in the Properties window. Add two text boxes to the form.</li>  In the Init method of the form, add the following code: * This menu defines the edit menu functions like Cut/Copy/Paste DO SdiEditMenu.mpr WITH THIS, .T.

* First you run the menu, then you DEACTIVATE it. * The menu definition remains in memory so the shortcut keys are * available DEACTIVATE MENU (THIS.Name) </li> Run the form. Type something in the first text box, then press Ctrl+X to cut whatever you typed in, and then press Ctrl+V to paste it in the second text box.</li></ol>

NOTE: Only menu options with shortcut keys in the Visual FoxPro system menu work for the above example. In this case only Cut, Copy, and Paste have shortcut keys.

Following is another example that uses the SYS(1500) function to accomplish the same behavior as above. SYS(1500), a new function, allows you to call a menu bar function without having the menu bar available:

<ol> Create a form, set the ShowWindow property for the form to "2 - As Top-Level Form", and name it SdiEditForm2.scx.</li> Add two text boxes to the form.</li>  In the Init method of the form, add the following code: *Activate the Paste menu bar when CTRL+V is press. ON KEY LABEL CTRL+V SYS(1500, '_MED_PASTE', '_MEDIT')

*Activate the Copy menu bar when CTRL+C is press. ON KEY LABEL CTRL+C SYS(1500,'_MED_COPY','_MEDIT')

*Activate the Cut menu bar when CTRL+X is press. ON KEY LABEL CTRL+X SYS(1500,'_MED_CUT','_MEDIT') </li> Run the form. Type something in the first text box, then press Ctrl+X to cut whatever you typed in, and then press Ctrl+V to paste it in the second text box.</li></ol>

<div class="references_section">