Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1096
  • Last Modified:

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!
0
PMH4514
Asked:
PMH4514
  • 2
  • 2
1 Solution
 
HooKooDooKuCommented:
Can you use SW_SHOWMAXIMIZED instead of SW_SHOWNORMAL?
0
 
Todd GerbertIT ConsultantCommented:
You could use CreateProcess instead of ShellExecute (if all you're doing is starting an EXE, and not e.g. pointing to a .doc file with the "open" verb).  CreateProcess will give you the process ID, which you can use in combination with EnumWindows() to get the HWND for the spawned application and call BringWindowToTop().
0
 
PMH4514Author 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!
0
 
Todd GerbertIT ConsultantCommented:
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.
0
 
PMH4514Author Commented:
thank you tgerbert - your original suggestion worked! I apologize for the delayed response.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now