Link to home
Start Free TrialLog in
Avatar of PMH4514
PMH4514

asked on

C++, ShellExecute, forcing new app to front

In Visual C++ 6.0, I call:

      HINSTANCE hInst = ShellExecute(NULL, NULL, sLaunch, sParams, NULL, SW_SHOWNORMAL);

where sLaunch is the fully qualified path to the executable, and sParams are command line params.

This works, the application runs as it should.  The problem is that sometimes the app loads, but it's not got focus - its icon in the windows taskbar is flashing.. Other times, it actually loads and comes to the front as it should.

How can I force the launched application to come up to the front so the user doesn't then have to recognize there is a flashing icon in the footer and click it?

My platforms of concern are XP Pro, and Win7
thanks!
Avatar of HooKooDooKu
HooKooDooKu

Can you use SW_SHOWMAXIMIZED instead of SW_SHOWNORMAL?
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PMH4514

ASKER

HookooDooKu - tried that, it didn't work.

tgerbert - that just might work. I'll give it a try, but will not be able to report back today due to scheduling. thanks!
I was mucking about with this a bit today and it seems using SetWindowPos() with HWND_TOPMOST set seems to most reliably bring the child process's window to the foreground.  The only little caveat that I see is that a given process may have more than one top-level window, so it's possible (depending on the child process you're starting) you might not accurately be able to determine the hWnd.
Avatar of PMH4514

ASKER

thank you tgerbert - your original suggestion worked! I apologize for the delayed response.