This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for

This function makes the specified top-level window associated with the thread calling this function the active window.


HWND SetActiveWindow(



[in] Handle to the top-level window to be activated.

Return Value

The handle to the window that was previously active indicates success. NULL indicates failure. To get extended error information, call GetLastError.


The SetActiveWindowfunction activates a window, but not if the application is in the background. The window will be brought into the foreground — the top of z-order — if the application is in the foreground when it sets the activation.

If the window identified by the hWndparameter 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.

For Windows CE 2.10 and later, if you call this function with hWndset to the handle of the child window, SetActiveWindowreturns NULL and sets the extended error value to zero.

The SetForegroundWindowwindow function, on the other hand, activates a window and forces it into the foreground. An application should only call SetForegroundWindowif it needs to display critical errors or information that needs the user's immediate attention.


Header winuser.h
Library Caret.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also