GetForegroundWindow Function

The GetForegroundWindow function returns 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 GetForegroundWindow(VOID);

Return Value

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.

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 :


Community Content

jmdavison
Another Case When GetForegroundWindow Returns NULL
I've been told that GetForegroundWindow will return NULL if the screen is locked.
Tags : contentbug

LinusR
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.
Tags : contentbug

Shital Shah
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?
Tags :

dmex
vb.net syntax
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetForegroundWindow() As IntPtr End Function
Tags :

dmex
C# syntax
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetForegroundWindow();
Tags :

Page view tracker