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

Scott Roberts please help! Displaying new window target in current window using MFC

0 views
Skip to first unread message

Murali Krishna Devarakonda

unread,
Jun 5, 1998, 3:00:00 AM6/5/98
to

I hate to bother you by bringing this question up again, and again, but I'm
lost with this issue, which you said is a bug.

You did post an article on 5/21 with a link to a Knowledge Base article
Q185538, that's in Visual Basic.

However, I'm unable to relate to it, as I have an MFC/SDI app using Visual
C++ 5.0, wherein I'm creating the WebBrowser2 control dynamically.

It would be a great help if you can show us (those of us who are still lost)
in Visual C++, how to handle OnNewWindow2 event correctly so that it's shown
in the current browser's view.

I've struggled with this issue ( just as I've struggled to figure out how to
implement anything related to the WebBrowser2 control, beyond the basic
Event Sink map).

Please Help!

Murali Krishna Devarakonda
e: Murali-Kris...@Cheerful.com
( remove ANTISPAM to send mail )

Simon C

unread,
Jun 5, 1998, 3:00:00 AM6/5/98
to

I believe I was the one who originally posted this question. Lots of thanks
to Scott, I was able to implement the VC version of the code. That code is
very long, and I don't think I can post the whole solution up here. A
similar solution targetted at a different problem was provided by Scott
himself on the June edition of MSJ, which can be download on MSJ's web page.
That is where I learn to code it myself.

Once you get the code, the key is to change DIID_DWebBrowserEvents2 to
DIID_DWebBrowserEvents. You can find the parameters of OnNewWindow by
openning shdocvw.dll as a type library in ClassWizzard. Also change
AfxConnectionAdvise to set to your interface other than IE4.

As a note of warning, there is something I found after doing all these work.
For some reason, if the script window.open() is executed in the html page,
this solution will have an exceptionally long load time before displaying
the new page in current window. So long that it looks like it halt. May be I
did something work here. Nevertheless, I end up discarding this solution
completely and implement a brouce back Dialog in NewWindow2 instead, which
is much simpler.

Respone to OnNewWindow2 event by creating a blank invisible dialog that
contains a browser control:

void CBrowser::OnNewWindow2Explorer1(LPDISPATCH FAR* ppDisp, BOOL FAR*
Cancel)
{
CBlankDlg* pBlankDlg = new CBlankDlg;
pBlankDlg->Create(IDD_BLANK_DLG);
pBlankDlg->m_parentDlg = this;

*ppDisp = pBlankDlg->m_WBrowser.GetApplication();
}


Then in the blank dialog, response to OnBeforeNavigate2:

void CBlankDlg::OnBeforeNavigate2Explorer1(LPDISPATCH pDisp, VARIANT FAR*
URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR*
PostData, VARIANT FAR* Headers, BOOL FAR* Cancel)
{
if (m_parentDlg)
{
COleVariant varEmpty;
m_parentDlg->m_WBrowser.Navigate2
(URL, &varEmpty, &varEmpty, &varEmpty, &varEmpty);
m_parentDlg = 0;
*Cancel = -1;
OnOK();
}
}

This isn't the cleanest solution. But it is simple, easy, and most
important, it works. Hope this will solve your problem.

Simon C

Murali Krishna Devarakonda wrote in message ...

David Roe

unread,
Jun 9, 1998, 3:00:00 AM6/9/98
to

> I believe I was the one who originally posted this question. Lots of
thanks
> to Scott, I was able to implement the VC version of the code. That code
is
> very long, and I don't think I can post the whole solution up here.

From previous posts in this and other newsgroups, this problem is one
facing a lot of people. I have not seen any C/C++ example code anywhere
that shows the solution.

If you could post your solution to this group, I'm sure a lot of people
would be very grateful. I, for one, would be on your doorstep, offering
child-bearing services. :-)

Rgds,
/David


Scott Roberts

unread,
Jun 10, 1998, 3:00:00 AM6/10/98
to

Hi guys,

Sorry I haven't responded. I've been really busy preparing for a talk I
gave at Tech-Ed 98. I wasn't able to monitor the newsgroups for a while.
If Simon, doesn't post code in a week, I'll come up with something.

Also, I've seen the problem Simon talks about. I'll see if I can find any
info on that.

Scott Roberts
Support Engineer/Content Lead
Microsoft Developer Support
---------------------


David Roe wrote in message <01bd9414$129d5700$035723cb@tali>...

Simon C

unread,
Jun 12, 1998, 3:00:00 AM6/12/98
to

I was working till 10pm last night and sorry that I haven't have the time to
reply earlier. When I check this newsgroup again, I was a bit shock that no
one accept the brounce back dialog which I am using in my framed program
now. Nonetheless, if everyone prefer the IE3EventSink solution, here it is.


1) Goto class wizzard and create a new class. Use CCmdTarget as your base
class and check Automation. I will use the name IE3Events.

2) In IE3Events.cpp file:
i) Add this to your DISPATCH_MAP:
DISP_FUNCTION_ID(CIE3Events, "NewWindow", DISPID_NEWWINDOW,
OnNewWindow, VT_EMPTY, VTS_BSTR VTS_I4 VTS_BSTR VTS_PVARIANT VTS_BSTR
VTS_PBOOL)


ii) In your INTERFACE_MAP, change IID_IIE3Events to DIID_DWebBrowserEvents.
You can delete the declaration for IID_IIE3Events (right above the INTERFACE
MAP) as well if you choose to.


iii) Assuming your webbrowser control is call m_WebBrowser2, add this
function:

void CIE3Events::OnNewWindow(LPCTSTR URL, long Flags, LPCTSTR
TargetFrameName, VARIANT FAR* PostData, LPCTSTR Headers, BOOL FAR*
Processed)
{
COleVariant varURL(URL), varEmpty;
*Processed = TRUE;
m_pParent->m_WebBrowser2.Navigate2 (&varURL, &varEmpty, &varEmpty,
&varEmpty, &varEmpty);
}

iv) Add #include "webbrowser2.h" and any needed .h header files and save
this IE3Events.cpp file.


3) In IE3Events.h file,
i) Add this code to your CIE3Events class:
public:
CWnd *m_pParent;
protected:
void OnNewWindow(LPCTSTR URL, long Flags, LPCTSTR TargetFrameName, VARIANT
FAR* PostData, LPCTSTR Headers, BOOL FAR* Processed);

iv) Save this IE3Events.h file.


4) Assuming the window that contains your webbrowser control is CDemoDlg,
open DemoDlg.h:
i) Add this to CDemoDlg class:
CIE3Events m_IE3Events;
DWORD m_dwCookie;

ii) Add #include "IE3Events.h" and save this DemoDlg.h file.


5) Open CDemoDlg.c,
i) Add this to your OnInitDialog:
m_IE3Events.m_pParent = this;
m_dwCookie = 0;
if (!(AfxConnectionAdvise(m_WebBrowser2->GetApplication(),
DIID_DWebBrowserEvents,
m_IE3Events.GetInterface(&IID_IUnknown), TRUE, &m_dwCookie)))
MessageBox ("Enter your error handling here.");

ii) Add this to your OnDestroy message handler. Create one using
ClassWizzard if your don't have one already:
if (m_dwCookie)
{
AfxConnectionUnadvise(m_WebBrowser2->GetApplication(),
DIID_DWebBrowserEvents,
m_IE3Events.GetInterface(&IID_IUnknown), TRUE, m_dwCookie);
m_dwCookie = 0;
}

iii) Save this CDemoDlg.c file.


This should be it. If you are using the variable names I have suggested, the
only thing need to be changed should be the web browser control variable
name from m_WebBrowser2 to m_yourCtrlName. Make the coresponding adjustment
if your control is in CWnd instead of CDialog.

If this is confusing, Scott Robert, whom the real credits should goes to,
have an "IE4" event sink sample code which has similar format as this one.
You can download that code in the June Edition of MSJ at www.msj.com . If
you encounter any problem with this IE3 event example, let me know promptly.
Until then, hope this can solve your problem.

Simon C

(Take it easy with me, I am just a UWaterloo coop student, okay?!)


Scott Roberts wrote in message
<#f64bmJl...@uppssnewspub04.moswest.msn.net>...

0 new messages