Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
Windowing
Windows
Windows Reference
Functions
 GetForegroundWindow Function
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 What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Another Case When GetForegroundWindow Returns NULL      jmdavison   |   Edit   |   Show History
I've been told that GetForegroundWindow will return NULL if the screen is locked.
Yet another case      LinusR   |   Edit   |   Show History
when GetForegroundWindow returns null is when you connect to a server with remote desktop and minimize your remote desktop window. It's very annoying.
What happens when there are two windows stacked side by side or on mult-monitor?      Shital Shah   |   Edit   |   Show History
Can there be two forground windows? Is there anyway to identiy windows which are full visible and not hidden behind other windows?
Tags What's this?: Add a tag
Flag as ContentBug
vb.net syntax      dmex   |   Edit   |   Show History
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetForegroundWindow() 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 GetForegroundWindow();
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