次の方法で共有


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

'宣言
Public Overridable Sub ShowContextMenu ( _
    menuId As Integer, _
    groupGuid As Guid, _
    target As IOleCommandTarget _
)
'使用
Dim instance As ViewFilter
Dim menuId As Integer
Dim groupGuid As Guid
Dim target As IOleCommandTarget

instance.ShowContextMenu(menuId, groupGuid, _
    target)
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.

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

See Also

Reference

ViewFilter Class

ViewFilter Members

ShowContextMenu Overload

Microsoft.VisualStudio.Package Namespace