Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting Context Menu Information

0 views
Skip to first unread message

Jamie S

unread,
Jul 16, 2004, 7:18:00 AM7/16/04
to
Hi,

Ive overridden the context menu and want to gain the URL, when a user
right clicks on a link (anchor).
However, although my code compiles fine, it crashes when
right-clicking on a link. I have narrowed the problem to my
queryinterface line. Has anyone got an idea of where i went wrong?
Thanks.

HRESULT FAR EXPORT CCustomControlSite::XDocHostUIHandler::ShowContextMenu(
DWORD dwID,
POINT* /*pptPosition*/,
IUnknown* /*pCommandTarget*/,
IDispatch *pdispReserved)
{
METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)

if (dwID == 6) //an anchor (works fine)
{
IHTMLAnchorElement *pElem = NULL;
BSTR bstrURL;

pdispReserved->QueryInterface(IID_IHTMLAnchorElement,(void**)&pElem);

pElem->get_href(&bstrURL);


}
else
AfxMessageBox("Default Menu");

return S_OK;
}

Igor Tandetnik

unread,
Jul 16, 2004, 10:22:47 AM7/16/04
to
"Jamie S" <crea...@hotmail.com> wrote in message
news:9f08a8a1.04071...@posting.google.com

> Ive overridden the context menu and want to gain the URL, when a user
> right clicks on a link (anchor).
> However, although my code compiles fine, it crashes when
> right-clicking on a link. I have narrowed the problem to my
> queryinterface line. Has anyone got an idea of where i went wrong?
>
> HRESULT FAR EXPORT
> CCustomControlSite::XDocHostUIHandler::ShowContextMenu( DWORD dwID,

It is strange that the function is not marked with __stdcall calling
convention. Usually, an interface method is declared with STDMETHODIMP
(which expands to __stdcall). I'm not familiar with MFC - does it
achieve the same effect in some other way?

> POINT* /*pptPosition*/,
> IUnknown* /*pCommandTarget*/,
> IDispatch *pdispReserved)
> {
> METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)
>
> if (dwID == 6) //an anchor (works fine)

6 is CONTEXT_MENU_UNKNOWN. An anchor would be CONTEXT_MENU_ANCHOR, which
is 5.

> {
> IHTMLAnchorElement *pElem = NULL;
> BSTR bstrURL;
>
> pdispReserved->QueryInterface(IID_IHTMLAnchorElement,(void**)&pElem);

Is pdispReserved NULL, by any chance?
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


0 new messages