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

WebBrowser Control - IDispatch::Invoke - DISPID_NEWWINDOW2

308 views
Skip to first unread message

Stephen Conner

unread,
Oct 2, 2000, 3:00:00 AM10/2/00
to

Ok, I have wrapped up the WebBrowser control and overridden the
IDispatch::Invoke method in my classes so that I can trap the Events of the
WebBrowser.

Note: This is all COM and ATL, no MFC, which is why I am trapping the events
through IDispatch..

Within my implementation of Invoke I am switching on the dispparams
parameter so I can trap the events. The one I am particularly interested in
at the moment is DISPID_NEWWINDOW2, which gets called when the Browser is
going to open a new window.

The brief documentation I have found about this says just return the
IDispatch of the current WebBrowser object. This is tried, without success.

This problem is bugging me now, any one out there know anything about
re-directing the Browser via the events trapped in Invoke. I would like to
re-use the existing browser and not open a new window.

Any ideas

Thanks

Steve Conner

Igor Tandetnik

unread,
Oct 2, 2000, 3:00:00 AM10/2/00
to

I'm afraid the only way to do it is to create a new instance of WebBrowser
control or InternetExplorer app, sink events from it and return its
interface pointer from NewWindow2 event. The first browser will then arrange
for the new instance to navigate. Eventually, you'll receive BeforeNavigate2
event from the new instance, supplying the URL as the parameter. At this
point, you can cancel the navigate in the new browser, destroy it and
navigate to this URL in the first browser.
--
With best wishes,
Igor Tandetnik

"Stephen Conner" <steve...@hotmail.com> wrote in message
news:uyK717G...@cppssbbsa02.microsoft.com...

Stephen Conner

unread,
Oct 2, 2000, 3:00:00 AM10/2/00
to

Yeah, thats what I figured from the documentation ....

But, I got doing this ...

case DISPID_NEWWINDOW2:
{
// Sent when a New Window should be created ...
CComPtr<IDispatch> pIDispatch;

m_spIWebBrowser2->get_Application(&pIDispatch);
*(pDispParams->rgvarg[1].ppdispVal) = pIDispatch;

m_bRemainInWindow = TRUE;

break;
}

This then forces a call to the DISPID_BEFORENAVIAGTE2
If you don't redirect the URL in BEFORENAVIGATE2 then nothing happens so;

case DISPID_BEFORENAVIGATE2:
{
// If m_bRemainInWindow has been set then we know we are frigging a NewWindow request ....
if (m_bRemainInWindow)
{
m_bRemainInWindow = FALSE;
CComVariant varURL(*pDispParams->rgvarg[5].pvarVal);
varURL.ChangeType(VT_BSTR);
SetURL(varURL.bstrVal); // My Function .... Could Be m_spIWebBrowser2->Navigate2(...)
}
break;
}


Steve Conner

"Igor Tandetnik" <itand...@whenu.com> wrote in message news:#t#JrwHLA...@cppssbbsa02.microsoft.com...

0 new messages