how to change iexplore background color dynamically

91 views Asked by At

I am launching Internet Explorer from my Win32 application as a separate process. Later, I want to change this Internet Explore's background color dynamically from my app. I can get the HWND of IEXPLORE.EXE:

HWND iexplor = GetForegroundWindow();   //assuming my explorer is active window currently

So, now with this HWND instance, is there a way I can change the background color of IEXPLORE?

Regular Win32 APIs fail because its a separate process (access denied).

Any idea/suggestions to this problem?

Below code fails because IE is a separate process:

HWND activeWindow = GetForegroundWindow();
if (activeWindow)
{
    HBRUSH brush = CreateSolidBrush(RGB(0, 0, 0));                  
    SetClassLongPtr(activeWindow, GCLP_HBRBACKGROUND, (LONG)brush);

    InvalidateRect(activeWindow, NULL, TRUE);
    int redraw =  ::UpdateWindow(activeWindow);
}
1

There are 1 answers

0
Remy Lebeau On

First, IE is not guaranteed to be in the foreground when you need it. You should instead enumerate the open HWND handles of the specific process that you are launching. Look at EnumThreadWindows(), EnumChildWindows(), etc.

Second, once you have the proper HWND to an IE window, you can get its IHTMLDocument2 interface, and then use IE's DOM interfaces to manipulate the browser's content as needed. Such as by setting the IHTMLDocument2::bgColor property. Or using the IHTMLDocument2::body property to retrieve the IHTMLBodyElement interface for the <body> element and then setting the IHTMLBodyElement::bgColor property.