ViewFilter.ShowContextMenu Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Handles the SHOWCONTEXTMENU command to show a context menu.
public:
virtual void ShowContextMenu(int menuId, Guid groupGuid, Microsoft::VisualStudio::OLE::Interop::IOleCommandTarget ^ target, int x, int y);
public virtual void ShowContextMenu (int menuId, Guid groupGuid, Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget target, int x, int y);
abstract member ShowContextMenu : int * Guid * Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget * int * int -> unit
override this.ShowContextMenu : int * Guid * Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget * int * int -> unit
Public Overridable Sub ShowContextMenu (menuId As Integer, groupGuid As Guid, target As IOleCommandTarget, x As Integer, y As Integer)
Parameters
- menuId
- Int32
[in] The ID of the menu to show.
- groupGuid
- Guid
[in] The GUID of the menu group from which the menu ID is taken.
- target
- IOleCommandTarget
[in] The IOleCommandTarget object that is to handle the commands in the context menu.
- x
- Int32
The x value of the point used in ShowContextMenu(UInt32, Guid, Int32, POINTS[], IOleCommandTarget).
- y
- Int32
The y value of the point used in ShowContextMenu(UInt32, Guid, Int32, POINTS[], IOleCommandTarget).
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;
}
}
}
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.