SetActiveWindow function (winuser.h)

Activates a window. The window must be attached to the calling thread's message queue.

Syntax

HWND SetActiveWindow(
  [in] HWND hWnd
);

Parameters

[in] hWnd

Type: HWND

A handle to the top-level window to be activated.

Return value

Type: HWND

If the function succeeds, the return value is the handle to the window that was previously active.

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

Remarks

The SetActiveWindow function activates a window, but not if the application is in the background. The window will be brought into the foreground (top of Z-Order) if its application is in the foreground when the system activates the window.

If the window identified by the hWnd parameter was created by the calling thread, the active window status of the calling thread is set to hWnd. Otherwise, the active window status of the calling thread is set to NULL.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll
API set ext-ms-win-ntuser-window-l1-1-4 (introduced in Windows 10, version 10.0.14393)

See also

Conceptual

GetActiveWindow

Keyboard Input

Reference

SetForegroundWindow

WM_ACTIVATE