ViewFilter.ShowContextMenu Method (Int32, Guid, IOleCommandTarget, Int32, Int32)
Handles the SHOWCONTEXTMENU command to show a context menu.
Namespace: Microsoft.VisualStudio.Package
Assemblies: Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)
Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
Syntax
'Declaration
Public Overridable Sub ShowContextMenu ( _
menuId As Integer, _
groupGuid As Guid, _
target As IOleCommandTarget, _
x As Integer, _
y As Integer _
)
public virtual void ShowContextMenu(
int menuId,
Guid groupGuid,
IOleCommandTarget target,
int x,
int y
)
public:
virtual void ShowContextMenu(
int menuId,
Guid groupGuid,
IOleCommandTarget^ target,
int x,
int y
)
abstract ShowContextMenu :
menuId:int *
groupGuid:Guid *
target:IOleCommandTarget *
x:int *
y:int -> unit
override ShowContextMenu :
menuId:int *
groupGuid:Guid *
target:IOleCommandTarget *
x:int *
y:int -> unit
public function ShowContextMenu(
menuId : int,
groupGuid : Guid,
target : IOleCommandTarget,
x : int,
y : int
)
Parameters
menuId
Type: Int32[in] The ID of the menu to show.
groupGuid
Type: Guid[in] The GUID of the menu group from which the menu ID is taken.
target
Type: Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget[in] The IOleCommandTarget object that is to handle the commands in the context menu.
x
Type: Int32The x value of the point used in ShowContextMenu.
y
Type: Int32The y value of the point used in ShowContextMenu.
Remarks
This method is called to handle a context menu in the current view. This provides an opportunity to display your own context menu or modify the existing menu and show it.
The base method is called with a menuID of IDM_VS_CTXT_CODEWIN, a groupGuid of guidSHLMainMenu, and a target of the IOleCommandTarget interface implemented on the ViewFilter class. The base method determines if macros are not being recorded and then shows the context menu.
Examples
Here is how the base ViewFilter class implements this method.
using System;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
namespace Microsoft.VisualStudio.Package
{
[CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public class ViewFilter :
IVsTextViewFilter,
IVsTextViewEvents,
IOleCommandTarget,
IDisposable
{
public virtual void ShowContextMenu(int menuId,
Guid groupGuid,
IOleCommandTarget target)
{
IVsUIShell uiShell = this.service.GetService(typeof(SVsUIShell)) as IVsUIShell;
// disable context menu while recording macros.
if (uiShell != null && !this.service.IsMacroRecordingOn())
{
System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
POINTS[] pnts = new POINTS[1];
pnts[0].x = (short)pt.X;
pnts[0].y = (short)pt.Y;
int hr = uiShell.ShowContextMenu(0, ref groupGuid, menuId, pnts, target);
if (hr < 0)
{
Debug.Assert(false, "uiShell.ShowContextMenu returned " + hr);
}
}
uiShell = null;
}
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.