We help IT Professionals succeed at work.

WebBrowser, Navigate and NewWindow2

cjs
cjs asked
on
Medium Priority
3,315 Views
Last Modified: 2013-11-20
I'm trying to use the WebBrowser control in the following way.  I want to call Navigate or Navigate2 with a path to a directory.  This works fine.  The problem is that I want the navigation to occur in the same window.  I don't want a new window to open.  I have set the flag in navigate to open a new window, so that I will get the NewWindow2 event.  I get this event OK. I then have tried to alter ppDisp so that the same window would be used to no avail. I either get an error, or I get a second window opened.   I've looked for examples of what I am trying to do and have found now.  The June MSJ article was no help either.

Thanks for any help.
Comment
Watch Question

Murali Devarakonda4WeekStartup.guru

Commented:
Navigate/Navigate2 both open a file in the same window by default. How are you using the WebBrowser control? Are you using VB or Visual C++ (if so, are you using MFC?).

If a new window is being created, you can make the browsing occur in the same window, but it requires a little bit of code, which I can give you. You're in luck if you are using VB- I can show you sample code which is much simpler for that too.

What I don't understand is that you say you don't want a new window to open, yet YOU are the one setting the flag to open a new window! Why? Explain.
cjs

Author

Commented:
Sorry, I was a bit misleading in the question.

I'm using MFC.

Yes, if I don't set the flag for opening a new window, then I get the desired action of having the navigation occur in the same window.  It's when I double click on an item in that window that I would like the navigation to again occur in the same window.  Instead, the navigation occurs in a second new window.  When this first happended I thought I would have to set the OpenNewWindow flag and then do something in the NewWindow2 event.

Summary:

The first navigations OK, its the ensuing navigations that occur due to mouse clicks that I want to occur in the same window.


4WeekStartup.guru
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Murali Devarakonda4WeekStartup.guru

Commented:
I think I haven't left out anything here, but it's possible.
Check out the knowledge base article, and also the online docuementation for NewWindow2.

Be sure to reset the value (and of course, intialize the first time) the value of the member variable used to hold the value of the URL.

cjs

Author

Commented:
I have implemented what you have suggested above.  Things work, and I understand the idea behind the hidden dialog.  The only thing that does not work is when I double click on an item in the explorer display, I don't get NewWindow or BeforeNavigate events.  A new window is created and displayed.  Is this related to the fact that the 'doc' type for a directory is another explorer, so it runs this instead?

Thanks for all your help so far. I feel Its so close now.

Murali Devarakonda4WeekStartup.guru

Commented:
That is a totally different problem requiring completely different solution.

I can tell you this much- you have to implement the IDocHostUIHandler interface.

Good luck.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.