Your method '1' actually works. The problem, at least here, is that 'Shell DocObject View' window is not an immediate child of the top-level ie window. Here with IE8, 'Internet Explorer_Server' window is a child of 'Shell DocObject View', which is a child of 'TabWindowClass', which is a child of 'Frame Tab'. If you can confirm 'FindWindowEx' returns 0 in method 1, that's why it fails. The below is the code modified to use EnumChildWindows:
function EnumChilds(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;
Server = 'Internet Explorer_Server';
ClassName: array[0..24] of Char;
GetClassName(hwnd, ClassName, Length(ClassName));
Result := ClassName <> Server;
if not Result then
PLongWord(lParam)^ := hwnd;
function GetActiveIEServerWindow(const Activate: Boolean=True): HWND;
Wnd, WndChild: HWND;
Result := 0;
Wnd := FindWindow('IEFrame', nil); // top level IE
if Wnd <> 0 then
// WndChild := FindWindowEx(Wnd, 0, 'Shell DocObject View', nil);
// if WndChild <> 0 then
// WndChild := FindWindowEx(WndChild, 0, 'Internet Explorer_Server', nil);
WndChild := 0;
EnumChildWindows(Wnd, @EnumChilds, LongWord(@WndChild));
if WndChild <> 0 then
Result := WndChild;
if Activate then
if IsIconic(Wnd) then
As for method '2', I've seen a few links on the web that state IE does not support returning a reference for its active object, but I don't have any official reference for that.
Hi, and thanks for the answer. I'm testing with IE6/XP. so the child window might be different here (It is not the issue). what is your default browser BTW?
But ie6 does not have tabs, $800 makes no sense to ie6. I'm using e8 as mentioned in the answer.
I know, I was hoping IE6 will ignore that (I have also tried to pass 0 as flag), and since I acquire the active IHTMLDocument2 I should be able to Navigate no?.
@kobik - Seems reasonable. I tested the code as I posted in a WM with XPSP2 and Ie6.0.2900.2180(SP2), the existing ie window navigated to the link without launching a new instance, and the flag caused no trouble at all. You're right about the window hieararchy BTW.
Well, I juts realized my IE6 installation is messed up. Thanks for the confirmation, and EnumChildWindows is really the way to go. +1 and accepted.