GetForegroundWindow function
Applies to: desktop apps only
Retrieves a handle to the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.
Syntax
HWND WINAPI GetForegroundWindow(void);
Parameters
This function has no parameters.
Return value
Type:
Type: HWND
The return value is a handle to the foreground window. The foreground window can be NULL in certain circumstances, such as when a window is losing activation.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- Reference
- SetForegroundWindow
- Conceptual
- Windows
Send comments about this topic to Microsoft
Build date: 2/3/2012
vb.net syntax
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetForegroundWindow() As IntPtr
End Function
C# syntax
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetForegroundWindow();
- 4/25/2009
- dmex
What happens when there are two windows stacked side by side or on mult-monitor?
Can there be two forground windows? Is there anyway to identiy windows which are full visible and not hidden behind other windows?
- 3/2/2009
- Shital Shah
Yet another case
when GetForegroundWindow returns null is when you connect to a server with remote desktop and minimize your remote desktop window. It's very annoying.
- 8/29/2008
- LinusR