Hi Netters,

I am hosting Internet Explorer using the WebBrowser ActiveX control. I made
my own custom AxHost subclass and have setup by hand the IWebBrowser,
IHTMLDocument2, DWebBrowserEvents2, and IHTMLElement interfaces. This all
works and I can display web pages in my control with no problem. (after
finding out that the VTable order for methods IS important!)

I was able to load the HTML onto the page dynamically by setting the
innerHTML property of the body IHTMLElement. This works OK, but there didn't
seem to be any way to utilize inline CSS styles. There is a method that
allows you to link a url based style sheet, but that would require a messy
disk presence for the style sheet.

The solution I found was to implement my own IStream interface, passing that
to the IHTMLDocument (via the IPersistStreamInit interface). I also
implemented a custom proxy class that takes a BCL System.IO.Stream class and
implements the IStream interfaces (similar to the private class in the
WinForms assembly). This works fine too, and now I have inline CSS styles.

The PROBLEM THAT I'M ENCOUNTERING is the refresh function of the browser.
Initially I Navigate to the about:blank url so that I can get a document
object. This works fine and I replace the document's contents with my custom
stream. The problem occurs when the user presses F5 or uses the rightclick
menu to refresh the page. Upon refresh, the document is refreshed back to
the blank document.

This must be a non trivial problem to solve because Lutz Roeder's Reflecter
has the same problem--click on the lower browser panel and hit F5. The
browser will blank out. If you navigate to a new tree node, the HTML data
comes back, but has the wrong background color. I assume that the background
color is set only once and the HTML is updated as needed.

I have brainstormed on some possible solutions and I would like a bit of
feedback (I have not tried any of these and some might not work):

1. Disable F5 through low level message processing using Hooks or
Control.WndProc or Control.PreProcessMessage. Essentially eat the
keystrokes.

2. Disable the right click context menu using the IDocHostUIHandler
interface. This involves implementing IOleClientSite as well. I will
probably implement this interface anyway because it has a number of
beneficial features.

These both can be implemented on a Form, but I am thinking that it might be
better to implement IOleClientSite on a user control or even on a raw
ContainerControl. This way I can have two browsers on the same form with
different IDocHostUIHandler behavior.

3. Disable the Refresh command at the root. Implement IOleCommandTarget on
the Ax container and filter out or disable the Refresh command. If this
technique works, this would have the beneficial effect of also disabling the
keyboard refresh case.

4. Somehow detecting the refresh process and reloading my page through the
IStream again. This might be possible through the WebBrowser control's
DownloadComplete event which fires after a Refresh. I will have to somehow
determine that the page that I want to display is gone and then reload it.

5. Do something with IDocHostUIHandler.TranslateAccelerated to filter out
F5. This would probably be preferable to option 1.

6. It would certainly be nice for the people who like to stream stuff to the
browser if there was a way to disable the refresh commnand!

I hope I haven't been too long winded...

--
Peter

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to