IOleComponentUIManager.ShowContextMenu Method


Requests the display of a context menu.

 int ShowContextMenu(System::UInt32 dwCompRole, Guid % rclsidActive, int nMenuId, cli::array <Microsoft::VisualStudio::Shell::Interop::POINTS> ^ pos, Microsoft::VisualStudio::OLE::Interop::IOleCommandTarget ^ pCmdTrgtActive);
public int ShowContextMenu (uint dwCompRole, ref Guid rclsidActive, int nMenuId, Microsoft.VisualStudio.Shell.Interop.POINTS[] pos, Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget pCmdTrgtActive);
abstract member ShowContextMenu : uint32 * Guid * int * Microsoft.VisualStudio.Shell.Interop.POINTS[] * Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget -> int
Public Function ShowContextMenu (dwCompRole As UInteger, ByRef rclsidActive As Guid, nMenuId As Integer, pos As POINTS(), pCmdTrgtActive As IOleCommandTarget) As Integer



[in] Role of the in-place VSPackage object requesting the context menu. For valid dwCompRole values, see OLEROLE.


[in] Class identifier (CLSID) of the in-place VSPackage object requesting the context menu.


[in] Identifies the context menu to be displayed.


[in] Identifies the screen position for the context menu.


[in] Points to the IOleCommandTarget interface to handle the dispatching of active object commands while the context menu is displayed.


If the method succeeds, it returns S_OK. If it fails, it returns an error code.


COM Signature

From oleipc.idl:

HRESULT IOleComponentUIManager::ShowContextMenu(  
   [in] DWORD dwCompRole,  
   [in] REFCLSID rclsidActive,  
   [in] LONG nMenuId,  
   [in] REFPOINTS pos,  
   [in] IOleCommandTarget *pCmdTrgtActive  

ShowContextMenu can be used by top-level tool objects and in-place VSPackage objects. In-place VSPackage objects must either be the innermost UI active object or a main or subcomponent in the parent chain of the UI active object.

When the context menu is no longer visible, the SOleComponentUIManager service returns to dispatching active object commands using the IOleCommandTarget interface of the inner-most active object. This is the object that was last passed in the call to IOleCommandTarget.

Because the IOleCommandTarget interface pointed to by pCmdTrgtActive is used while the context menu is displayed instead of the interface of the currently UI active object, it is possible to display the context menu without taking focus away from a nested control. Before displaying the requested menu, if the request is coming from an object acting as a sub in-place component or a component control, the SOleComponentUIManager service gives the main in-place component a chance to override or merge a container menu with the active object menu.

Invoking the command that the user selects on the context menu occurs before the call to ShowContextMenu returns.

If a VSPackage object acting as a component control wants the main component to display its generic control context menu, the component control calls IOleCommandTarget, supplying its own GUID and the menu identifier COMP_CONTEXTID_CTRLGENERIC. The SOleComponentUIManager service passes these identifiers on to the main component when it calls the object's GetCntrContextMenu. The main component should recognize this menu identifier and respond by suppressing the component control's menu and replacing it with the main component's generic control menu.

Applies to