GetActiveWindow function
Applies to: desktop apps only
Retrieves the window handle to the active window attached to the calling thread's message queue.
Syntax
HWND WINAPI GetActiveWindow(void);
Parameters
This function has no parameters.
Return value
Type: HWND
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.
To get the window handle to the active window in the message queue for another thread, use GetGUIThreadInfo.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- Reference
- GetForegroundWindow
- GetGUIThreadInfo
- SetActiveWindow
- Conceptual
- Keyboard Input
Send comments about this topic to Microsoft
Build date: 3/6/2012
Community Content
dmex
vb.net syntax
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetActiveWindow() As IntPtr
End Function
dmex
C# syntax
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetActiveWindow();
Goatspawn
Documentation incorrect
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.
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.