Board index » cppbuilder » IWebBrowser2 questions

IWebBrowser2 questions

I'm using the WebBrowser ActiveX component, and I want to disable the right
click popup menu in the component. Usually when a user right clicks, a popup
menu pops up, with options like "Open in New Window". I've tried trapping
mouse messages, but that doesn't seem to work.
Also, I want to show the standard Toolbar, I understand that this should be
done with ShowBrowserBar, but since I have no ActiveX/OLE experience, I have
no idea how to use this.

Any help/hints appreciated..
Thanx, Snoox

 

Re:IWebBrowser2 questions


Bruno
Hello Bruno

Re:IWebBrowser2 questions


You have to overwrite the UIHandler of the current received document when
the NavigateComplete2 event has been fired.

You can write something like:
// The  browser event
void __fastcall TMyForm::MyWebBrowserNavigateComplete2(TObject *Sender,
LPDISPATCH pDisp, TVariant *URL)
{
      // Remove context menu on this page
      LPDISPATCH plDispatch = MyWebBrowser->Document;
      ICustomDoc* pCustomDoc;
      plDispatch->QueryInterface(IID_ICustomDoc,(LPVOID*)&pCustomDoc);
      TDocHostUIHandler* pDHUIH = new TDocHostUIHandler();
      pCustomDoc->SetUIHandler((IDocHostUIHandler*)pDHUIH);
      pCustomDoc->Release();
      plDispatch->Release();

Quote
}

The TDocHostUIHandler object must be rewritten to return only a S_OK without
building the context menu.
A part of the CPP file containing the implementation of the DocHostUIHandler
should be:

TDocHostUIHandler::TDocHostUIHandler()
{
//

Quote
}

TDocHostUIHandler::~TDocHostUIHandler()
{
//

Quote
}

HRESULT STDMETHODCALLTYPE TDocHostUIHandler::ShowContextMenu(
            /* [in] */ DWORD dwID,
            /* [in] */ POINT __RPC_FAR *ppt,
            /* [in] */ IUnknown __RPC_FAR *pcmdtReserved,
            /* [in] */ IDispatch __RPC_FAR *pdispReserved)
{
 return S_OK;

Quote
}

If you want more information you should go to the MSDN site at:
http://msdn.microsoft.com/workshop/browser/default.asp

Bruno

Re:IWebBrowser2 questions


Hi Bruno,

Thanx for your help, but I can't figure out how to use your examples. I'm
not stupid, but have just NO experience with ole/com/activex whatsoever.
I've already checked msdn, but of course they have no vcl answers. Would you
be able to send me a working example? Would be greatly appreaciated if you
could cause I'm completely stuck..

Regards,
Mathijs Snoeks
email: sn...@chat2me.com

Re:IWebBrowser2 questions


I've been trying now for some time to implement the IDocHostUI handler as
described in the MSDN pages, but to no avail.  Does anyone know if there are
Borland builder based examples on the Net?  If so, where are they?  (I'm
rapidly loosing hair over this problem!)

Any help will be much appreciated,
Nick.

Quote
Bruno Laffont <laffo...@sekoya.net> wrote in message

news:7q72rv$s1u14@forums.borland.com...
Quote
> You have to overwrite the UIHandler of the current received document when
> the NavigateComplete2 event has been fired.

> You can write something like:
> // The  browser event
> void __fastcall TMyForm::MyWebBrowserNavigateComplete2(TObject *Sender,
> LPDISPATCH pDisp, TVariant *URL)
> {
>       // Remove context menu on this page
>       LPDISPATCH plDispatch = MyWebBrowser->Document;
>       ICustomDoc* pCustomDoc;
>       plDispatch->QueryInterface(IID_ICustomDoc,(LPVOID*)&pCustomDoc);
>       TDocHostUIHandler* pDHUIH = new TDocHostUIHandler();
>       pCustomDoc->SetUIHandler((IDocHostUIHandler*)pDHUIH);
>       pCustomDoc->Release();
>       plDispatch->Release();
> }

> The TDocHostUIHandler object must be rewritten to return only a S_OK
without
> building the context menu.
> A part of the CPP file containing the implementation of the
DocHostUIHandler
> should be:

> TDocHostUIHandler::TDocHostUIHandler()
> {
> //
> }

> TDocHostUIHandler::~TDocHostUIHandler()
> {
> //
> }

> HRESULT STDMETHODCALLTYPE TDocHostUIHandler::ShowContextMenu(
>             /* [in] */ DWORD dwID,
>             /* [in] */ POINT __RPC_FAR *ppt,
>             /* [in] */ IUnknown __RPC_FAR *pcmdtReserved,
>             /* [in] */ IDispatch __RPC_FAR *pdispReserved)
> {
>  return S_OK;
> }

> If you want more information you should go to the MSDN site at:
> http://msdn.microsoft.com/workshop/browser/default.asp

> Bruno

Other Threads