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

Windows Overview, SetForegroundWindow
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Another Case When GetForegroundWindow Returns NULL      jmdavison83   |   Edit   |  
I've been told that GetForegroundWindow will return NULL if the screen is locked.
Tags What's this?: Add a tag
Flag as ContentBug
Yet another case      LinusR   |   Edit   |  
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 What's this?: Add a tag
Flag as ContentBug
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker