Hello Bob,
Thanks for using Microsoft Newsgroup. This is Ji Zhou - MSFT and I will be
working on the issue with you.
Yes, Windows system use a z-order stack to managed the Windows position in
z-axis. But the z-order stack is managed by system as per the default
management approach. There are two ways to change the z-order stack of the
Windows,
1. Manually by user mouse/keyboard input.
2. Programmatically by program automation.
To bring the B application's window in front programmatically, we need to
call SetForegroundWindow API. Before we call application B's function to
create a new window, from application A, we should call SetForegroundWindow
to activate B's main form.
We can get more information about Foreground and Background Windows from
the following documentations,
http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx#foreground
http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx
For your convenience, I post the important part of documentation here,
-------------------------------------------------
"Each process can have multiple threads of execution, and each thread can
create windows. The thread that created the window with which the user is
currently working is called the foreground thread, and the window is called
the foreground window. All other threads are background threads, and the
windows created by background threads are called background windows.
Each thread has a priority level that determines the amount of CPU time the
thread receives. Although an application can set the priority level of its
threads, normally the foreground thread has a slightly higher priority
level than the background threads. Because it has a higher priority, the
foreground thread receives more CPU time than the background threads. The
foreground thread has a normal base priority of 9; a background thread has
a normal base priority of 7.
The user sets the foreground window by clicking a window, or by using the
ALT+TAB or ALT+ESC key combination. To retrieve a handle to the foreground
window, use the GetForegroundWindow function. To check if your application
window is the foreground window, compare the handle returned by
GetForegroundWindow to that of your application window.
An application sets the foreground window by using the SetForegroundWindow
function.
Windows NT 4.0 and earlier, Windows 95: If the new foreground window is a
top-level window, the system activates it; otherwise, it activates the
associated top-level window.
Windows 98/Me/2000/XP: The system restricts which processes can set the
foreground window. A process can set the foreground window only if one of
the following conditions is true:
The process is the foreground process.
The process was started by the foreground process.
The process received the last input event.
There is no foreground process.
The foreground process is being debugged.
The foreground is not locked (see LockSetForegroundWindow).
The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT
in SystemParametersInfo).
Windows 2000/XP: No menus are active.
Windows 2000/XP: A process that can set the foreground window can enable
another process to set the foreground window by calling the
AllowSetForegroundWindow function, or by calling the BroadcastSystemMessage
function with the BSF_ALLOWSFW flag. The foreground process can disable
calls to SetForegroundWindow by calling the LockSetForegroundWindow
function.
"
----------------------------------------------------------------
If you have any future questions or concerns, please feel free to let me
know. Have a nice day!
Best regards,
Ji Zhou
Microsoft Online Support Team