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);
}
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 atEnumThreadWindows()
,EnumChildWindows()
, etc.Second, once you have the proper
HWND
to an IE window, you can get itsIHTMLDocument2
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 theIHTMLDocument2::body
property to retrieve theIHTMLBodyElement
interface for the<body>
element and then setting the IHTMLBodyElement::bgColor property.