Tech Support > Microsoft Windows > Development Resources > Bringing Background Process to the Foreground
Bringing Background Process to the Foreground
Posted by BradPoster@comcast.net on December 16th, 2004


I've read a lot of material about this on the net and I'm still not
clear on what is possible and what is not.

I have a console application (call it A) (SUBSYSTEM=CONSOLE - has a
main() function). It creates another process (call it B) that is a
windows application (SUBSYSTEM=WINDOWS - has a WinMain() function).

B eventually creates windows, but these windows do not come to the
foreground and are otherwise uncontrollable with respect to stacking.
I can't make SetWindowPos have any effect, except when using
HWND_TOPMOST, which really isn't what I want. The windows tend to
appear at the bottom of the window stack, behind other windows, but
this behavior isn't particularily consistent.

What I WANT to have happen is for process B to create and control
windows that behave exactly as if process B had been started through a
"normal" launch process, i.e., via a shortcut or start menu item, etc.

I have tried the following:

- Immediately after process A creates process B, process A calls
AllowSetForegroundWindow with the process B handle as the parameter.
This function returns true as a result.

- Immediately after process B creates and shows a window, it calls
SetForegroundWindow using the handle of the window just created. This
function returns false and the new window doesn't behave any
differently than when I didn't add these two steps.

Is this the right approach? If not, what is?

I also noted that someone suggested that the window (the one process B
has created) can be created in an iconified state and then raised to
bring it to the foreground. I haven't tried it yet, but is this an
acceptable approach? I know that there may be a little extra
distraction as the window is raised.

Thanks in advance,
Brad


Similar Posts