A version of this page is also available for
This function puts the thread that created the specified window into the foreground and activates the window.
BOOL SetForegroundWindow( HWND hWnd );
[in] Handle to the window that should be activated and brought to the foreground. For more information, see the Remarks section.
Nonzero indicates that the window was brought to the foreground. Zero indicates that the window was not brought to the foreground.
The foreground window is the window at the top of the z-order. It is the window that the user is working with. In a preemptive multitasking environment, you should generally let the user control which window is the foreground window.
The thread that owns the window is not given a priority boost.
If the window being set to the foreground is minimized, the window may not be visible to the end user. To restore the window to a visible state, ShowWindow should be called.
This function does not reactivate the last active owned window by default. To ensure that the last active owned window is reactivated, combine the window handle with 0x01 using the logical OR operator. For example:
SetForegroundWindow((HWND)(((ULONG) hwnd) | 0x01) );
Calling PeekMessage before the top level window of an application is created will result in the window being created at the back of the z-order. You will need to explicitly call SetForegroundWindow to show the window when it is created after a call to PeekMessage. If the application already has a window in the foreground, then the new window will be created in the foreground.
SetForegroundWindow should not be called on child windows.
|Windows Embedded CE||Windows CE 1.0 and later|
|Windows Mobile||Windows Mobile Version 5.0 and later|