Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
User Input
Keyboard Input
Functions
 GetActiveWindow Function
GetActiveWindow Function

The GetActiveWindow function retrieves the window handle to the active window attached to the calling thread's message queue.

Syntax

HWND GetActiveWindow(VOID);

Return Value

The return value is the handle to the active window attached to the calling thread's message queue. Otherwise, the return value is NULL.

Remarks

To get the handle to the foreground window, you can use GetForegroundWindow.

Windows 98/Me and Windows NT 4.0 SP3 and later: To get the window handle to the active window in the message queue for another thread, use GetGUIThreadInfo.

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 3.1

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Documentation incorrect      Goatspawn   |   Edit   |   Show History
The documentation for this function isn't accurate, or is at least very confusing. The documentation seems to imply that each thread's messaging queue can have, independently, its own "active" window, regardless of what is the global active window that is actually receiving user input. This does not seem to be the case.

A system has only one active window, which GetForegroundWindow() returns. GetActiveWindow() seems to return the same window as GetForegroundWindow() if the foreground window belongs to the current thread. Otherwise, it always returns null, rather than the topmost window of the calling thread.
vb.net syntax      dmex   |   Edit   |   Show History
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetActiveWindow() As IntPtr End Function
Tags What's this?: Add a tag
Flag as ContentBug
C# syntax      dmex   |   Edit   |   Show History
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetActiveWindow();
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker