Compartir a través de


Display Shortcut Menus Sample

File: ...\Samples\Solution\Menus\Shortcut.scx

This sample illustrates displaying shortcut menus when a user "right-clicks" an object. When you have created a shortcut menu in the Menu Designer, the code in the form to activate the menu is very simple. The following code is associated with the RightClick event of the form:

DO frmshort.mpr WITH THIS

The following code is associated with the RightClick event of the edit boxes on the form:

DO edtshort.mpr WITH THIS

The FRMSHORT Menu

The FRMSHORT menu was designed to take an object parameter. The following code is included in the menu's setup code:

PARAMETER oREF
#PREPOP

The #PREPOP generative directive causes the code in the menu's cleanup to be generated before the ACTIVATE POPUP command. This makes it possible for you to disable or enable menu items at run time, as well as display check marks beside menu items.

The code associated with the menu items sets properties of the object that was passed to the .mpr as a parameter. For example, the Always on top item sets the AlwaysOnTop property of the form.

The following code, included in the menu's cleanup code, displays a check mark beside the Always on top item when the form's AlwaysOnTop property is set to true (.T.).

SET MARK OF BAR 4 OF frmshort TO oRef.AlwaysOnTop

The EDTSHORT Menu

The EDTSHORT menu also accepts an object parameter in its setup code. Because there is no need to display a check mark beside the items in this menu, the #PREPOP generator directive is not used.

For an alternative way to display shortcut menus, see the Create Dynamic Shortcut Menus sample.

See Also

Tasks

Solution Samples

Create Dynamic Shortcut Menus Sample

Reference

Visual FoxPro Foundation Classes A-Z

Other Resources

Menus and Toolbars Solution Samples