Overview
Group
Quick Info

Windows NT
Yes
Win95
Yes
Win32s
No
Import Library
user32.lib
Header File
winuser.h
Unicode
No
Platform Notes
None

SetForegroundWindow

The SetForegroundWindow function puts the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user.

BOOL SetForegroundWindow(

HWND hWnd
// handle of window to bring to foreground
);

Parameters

hWnd

Identifies the window that should be activated and brought to the foreground.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

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. However, an application can call SetForegroundWindow if it wants to put itself into the foreground to display a critical error or information that requires the user's immediate attention. A good example is a debugger when it hits a breakpoint.

The system assigns a slightly higher priority to the thread that created the foreground window than it does to other threads.

See Also

GetForegroundWindow

Comment from Greatis Sofware

If you're programming since 16-bit Windows systems age, then you might know that you can easily activate an application by calling SetActiveWindow function with handle of window, that you need to bring to front. In 16-bit Windows there were only one active window and one input focus in whole system. And these statuses were simply exchanging between windows and application controls. The golden years... Then, 32-bit systems came out with their idea of threads full independence. Now, every thread has its own active window and input focus, and SetWindow function still makes window active... in its thread. It does not affect activity of thread itself, so, there's no any practical benefit in it. What's useful in the fact, that some window in the application, that is in bottom, becomes above others? It looks like Microsoft have noticed that, and created SetForegroundWindow function, which, luckely, works in 32-bit systems very similar to SetActiveWindow in 16-bit. However, absolute happiness can't exist in Windows and SetForegroundWindow works undergraduate in Windows98 and Windows2000. Fortunately, these systems become more and more rare.

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database