Search code examples
c++windowsiwebbrowser2

How do I set a background colour for IWebBrowser2 whilst page is loading?


The title says it all really...

I'm using IWebBrowser2 to display web pages in my application, however, when I call IWebBrowser2::Navigate() a white background is displayed whilst the target page is loading, which conflicts with the colour scheme of my app.

I tried creating a "background.html" and pre-loading that before calling Navigate(), but as soon as I navigate to the new URL, the background changes to white.


Solution

  • This is untested:

    1. Hide the browser window. As I remember calling ShowWindow(SW_HIDE) would not work because the browser control doesn't do anything when its window is hidden. Instead you could MoveWindow() it outside of the client area to effectively hide it while it still thinks it is visible.
    2. Draw your custom background in the parent window of the browser control.
    3. Call IWebBrowser2::Navigate()
    4. Handle the NavigateComplete event where you show the browser window again. It should quickly redraw itself without first showing white background.