Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Hosting and Reuse
Interfaces
IDocHostUIHandler
 ShowContextMenu Method
IDocHostUIHandler::ShowContextMenu Method

Enables MSHTML to display a shortcut menu.

Syntax

HRESULT ShowContextMenu(      
    DWORD dwID,     POINT *ppt,     IUnknown *pcmdtReserved,     IDispatch *pdispReserved );

Parameters

dwID
[in] A DWORD that specifies the identifier of the shortcut menu to be displayed. These values are defined in Mshtmhst.h.
CONTEXT_MENU_DEFAULT
The default shortcut menu for a Web page.
CONTEXT_MENU_IMAGE
Shortcut menu for images.
CONTEXT_MENU_CONTROL
Shortcut menu for scrollbars and select elements.
CONTEXT_MENU_TABLE
Not used.
CONTEXT_MENU_TEXTSELECT
Shortcut menu for selected text.
CONTEXT_MENU_ANCHOR
Shortcut menu for hyperlinks.
CONTEXT_MENU_UNKNOWN
Not used.
ppt
[in] A pointer to a POINT structure containing the screen coordinates for the menu.
pcmdtReserved
[in] A pointer to the IUnknown of an IOleCommandTarget interface used to query command status and execute commands on this object.
pdispReserved
[in] A pointer to an IDispatch interface of the object at the screen coordinates specified in ppt. This enables a host to pass particular objects, such as anchor tags and images, to provide more specific context.

Return Value

Returns one of the following values.

S_OKHost displayed its user interface (UI). MSHTML will not attempt to display its UI.
S_FALSEHost did not display its UI. MSHTML will display its UI.
DOCHOST_E_UNKNOWNMenu identifier is unknown. MSHTML might attempt an alternative identifier from a previous version.

Remarks

In Microsoft Internet Explorer 4.0, the pdispReserved parameter supplied no information. In Internet Explorer 5 and later, the parameter contains the pointer to an IDispatch interface.

Example

The following code example shows how to use the pdispReserved parameter to access the interface of the object targeted by the context menu. The code queries for an IHTMLElement interface, and displays the value of its tagName property as debug output.

if (pdispReserved)
{
    IHTMLElement *pElem;
    HRESULT hr = pdispReserved->QueryInterface(
                IID_IHTMLElement, 
                (void**)&pElem);
    if (SUCCEEDED (hr))
    {
        BSTR bstr;
        pElem->get_tagName(&bstr);
        USES_CONVERSION;
        ATLTRACE("TagName:%s\n", OLE2T(bstr));
        SysFreeString(bstr);
        pElem->Release();
    }
}

See Also

About the Browser: Controlling the Context Menus
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
dwID incorrectly documented      DaveMethvin   |   Edit   |   Show History
The dwID argument does not appear to be documented correctly. If I select some text and right-click, dwID comes in as 0x04, which is the value of CONTEXT_MENU_TEXTSELECT documented in mshtmhst.h. However, this documentation says the value should be 0x10 which is incorrect.

Edit: The docs above have now been fixed.
Example result      Petr_HP   |   Edit   |   Show History
To the example: in bstr is always "BODY" in CHtmlView::ShowContextMenu. Is value of pdispReserved in CHtmlView version correct?
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker