ViewFilter.ShowContextMenu Method (Int32, Guid, IOleCommandTarget)
Handles the SHOWCONTEXTMENU command to show a context menu.
Namespace: Microsoft.VisualStudio.Package
Assembly: Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
Syntax
'Declaration
Public Overridable Sub ShowContextMenu ( _
menuId As Integer, _
groupGuid As Guid, _
target As IOleCommandTarget _
)
public virtual void ShowContextMenu(
int menuId,
Guid groupGuid,
IOleCommandTarget target
)
public:
virtual void ShowContextMenu(
int menuId,
Guid groupGuid,
IOleCommandTarget^ target
)
abstract ShowContextMenu :
menuId:int *
groupGuid:Guid *
target:IOleCommandTarget -> unit
override ShowContextMenu :
menuId:int *
groupGuid:Guid *
target:IOleCommandTarget -> unit
public function ShowContextMenu(
menuId : int,
groupGuid : Guid,
target : IOleCommandTarget
)
Parameters
menuId
Type: System.Int32[in] The ID of the menu to show.
groupGuid
Type: System.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.
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.