We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

C++, ShellExecute, forcing new app to front

PMH4514
PMH4514 asked
on
Medium Priority
1,392 Views
Last Modified: 2012-05-11
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!
Comment
Watch Question

CERTIFIED EXPERT

Commented:
Can you use SW_SHOWMAXIMIZED instead of SW_SHOWNORMAL?
Senior Engineer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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!
Todd GerbertSenior Engineer
CERTIFIED EXPERT
Top Expert 2010

Commented:
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.

Author

Commented:
thank you tgerbert - your original suggestion worked! I apologize for the delayed response.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.