Focus problem w/ OLE automating IE

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Dietmar Jäckle (Jäckle_at_discussions.microsoft.com)
Date: 08/19/04


Date: Thu, 19 Aug 2004 11:57:03 -0700

I am trying to launch IE from a C++ Application with the following
requirements:

- call a file URL with parameters like 'file://c:/index.html?a=b'
- subsequent calls should open new IE windows, but all running in the same
process (page contains a Java Applet and all Applets must run on the same VM
instance)
- new windows must always come to front

I tried ShellExecute and DDE, but I couldn't pass parameters that way.

My OLE Solution works fine for the first call, but on a second call, the new
IE win stays in the background.

Problem: In certain cases my applet must show a message dialog (Java Swing)
on startup, but when the IE win isn't on top (activated), the taskbar button
just blinks.
Now, if i use the taskbar to bring IE to front, the Applet hangs and IE must
be killed using the task manager. If I click on the IE Titlebar, the dialog
shows up correctly.

I suppose the solution would be to find a way to always bring new IE windows
to front, but as an OLE newbie I can't figure out how.

here's my source code:
----------
Browser* pOLE = new Browser;
BOOL rc = pOLE->CreateDispatch("InternetExplorer.Application");
COleVariant noArg;
pOLE->Navigate(strURL, &noArg, &noArg, &noArg, &noArg);
pOLE->SetVisible(TRUE);
pOLE->ReleaseDispatch();
---------
(Browser is of course my wrapper class for IWebBrowser2 from shdocvw.dll)

your help will be gladly appreciated


Quantcast