SetActiveWindow function

Expand
4 out of 6 rated this helpful - Rate this topic

SetActiveWindow function

Applies to: desktop apps only

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

Syntax

HWND WINAPI SetActiveWindow(
  __in  HWND hWnd
);

Parameters

hWnd [in]

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

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
GetActiveWindow
SetForegroundWindow
WM_ACTIVATE
Conceptual
Keyboard Input

 

 

Send comments about this topic to Microsoft

Build date: 5/5/2012

Did you find this helpful?
(1500 characters remaining)
Community Additions ADD
Freezing Issues with SetActiveWindow
From experience when using WinAPI calls, I have learned that SetActiveWindow can cause your window to freeze.  I believe this happens because the calls being made within the function are SendMessage calls vs. PostMessage calls where SendMessage may not return to your application.  If this issue comes up, try utilizing SetForegroundWindow instead.
6/9/2011