Export (0) Print
Expand All
1 out of 3 rated this helpful - Rate this topic

ShowContextMenu method

Enables MSHTML to display a shortcut menu.

Syntax


HRESULT retVal = object.ShowContextMenu(dwID, ppt, pcmdtReserved, pdispReserved);

Parameters

dwID [in]

Type: DWORD

A DWORD that specifies the identifier of the shortcut menu to be displayed. These values are defined in Mshtmhst.h.

CONTEXT_MENU_DEFAULT (0x0)

The default shortcut menu for a Web page.

CONTEXT_MENU_IMAGE (0x1)

Shortcut menu for images.

CONTEXT_MENU_CONTROL (0x2)

Shortcut menu for scrollbars and select elements.

CONTEXT_MENU_TABLE (0x3)

Not used.

CONTEXT_MENU_TEXTSELECT (0x4)

Shortcut menu for selected text.

CONTEXT_MENU_ANCHOR (0x5)

Shortcut menu for hyperlinks.

CONTEXT_MENU_UNKNOWN (0x6)

Not used.

CONTEXT_MENU_VSCROLL (0x9)

Shortcut menu for vertical scroll bar.

CONTEXT_MENU_HSCROLL (0x10)

Shortcut menu for horizontal scroll bar.

CONTEXT_MENU_MEDIA (0x11)

Internet Explorer 9 and later. Shortcut menu for media element controls.

ppt [in]

Type: POINT

A pointer to a POINT structure containing the screen coordinates for the menu.

pcmdtReserved [in]

Type: IUnknown

A pointer to the IUnknown of an IOleCommandTarget interface used to query command status and execute commands on this object.

pdispReserved [in]

Type: IDispatch

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.

Remarks

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

Examples

The following example shows how to prevent all shortcut menus except the text selection and control menus.


HRESULT CMyUIHandler::ShowContextMenu(
    DWORD dwID,
    POINT *ppt,
    IUnknown *pcmdtReserved,
    IDispatch *pdispReserved)
{
    // Do not show context menus by default with S_OK.
    HRESULT hr(S_OK);

    // If text select or control menu, then return S_FALSE to show menu.
    if( dwID == CONTEXT_MENU_TEXTSELECT || 
        dwID == CONTEXT_MENU_CONTROL)
        hr = S_FALSE;

    return hr;
}

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 IHTMLElement::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

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.