Displays a context menu at the given mouse point.

Syntax

Send_Message(Ctrl, "OLE.ShowContextMenu", Point, MenuStructure, UserData)

Parameters

ParameterDescription
PointThe mouse coordinate relative to the control's top left corner
MenuStructureThe structure defining the menu to appear
UserDataCustom data that will be passed to the context menu event

Remarks

The ShowContextMenu method displays a context menu anywhere on the surface of the control. Start by passing the mouse coordinates relative to the top left corner of the control. So, "0,0" places the context menu in the top left corner. The Point parameter can use either the comma or @FM for the delimiter.

The MenuStructure parameter describes the menu to appear. Each field represents on menu item. Each item has three values. The first value is any unique key or value you want to use to refer to the item later. The second value is the text to appear. For example, you can have an item whose key is "1" and text is "Copy". Or, the key could be "COPY" instead of "1". Whatever you pass is fine, as it will simply be forwarded onto the OnContextMenuClick event so you know exactly what was clicked. The third value is a flag indicating whether or not the menu item is enabled. This is useful for showing all available options but keeping certain ones enabled only when necessary. You can omit the third value, in which case the menu item will be enabled.

If you want a separator, pass an empty field. See the example below.

The UserData parameter is added for convenience. This is useful for passing something unique to this control so that you can have a generic event handler make certain decisions. A table control might pass a cell coordinate and a hyperlink control might pass a string indicating it's type. It doesn't really affect the operation of the context menu; it's just for your convenience.

Example

// Show a context menu with Paste disabled since the clipboard is empty
Menu = "" 
Menu<-1> = "CUT"    :@VM:"Cut"     :@VM:1
Menu<-1> = "COPY"   :@VM:"Copy"    :@VM:1
Menu<-1> = "PASTE"  :@VM:"Paste"   :@VM:0   ; // Disabled
Menu<-1> = ""                               ; // Separator 
Menu<-1> = "ZOOMIN" :@VM:"Zoom In" :@VM:1
Menu<-1> = "ZOOMOUT":@VM:"Zoom Out":@VM:1 

Send_Message(Ctrl, "OLE.ShowContextMenu", "10,10", Menu, "My Special Data")

See Also

OnContextMenuClick

  • No labels