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_OK | Host displayed its user interface (UI). MSHTML will not attempt to display its UI. |
| S_FALSE | Host did not display its UI. MSHTML will display its UI. |
| DOCHOST_E_UNKNOWN | Menu 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