Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
Windowing
Windows
Windows Reference
Functions
 WindowFromPoint Function
WindowFromPoint Function

The WindowFromPoint function retrieves a handle to the window that contains the specified point.

Syntax

HWND WindowFromPoint(      
    POINT Point );

Parameters

Point
[in] Specifies a POINT structure that defines the point to be checked.

Return Value

The return value is a handle to the window that contains the point. If no window exists at the given point, the return value is NULL. If the point is over a static text control, the return value is a handle to the window under the static text control.

Remarks

The WindowFromPoint function does not retrieve a handle to a hidden or disabled window, even if the point is within the window. An application should use the ChildWindowFromPoint function for a nonrestrictive search.

Example

For an example, see "Interface from Running Object Table" in About Text Object Model.

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
UnicodeImplemented as Unicode version.

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
C# declaration and example      deodorant   |   Edit   |   Show History

The code below shows an example of how to use WindowFromPoint mixed with GetCursorPos to get the window your mouse is hovered over.

[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(Point lpPoint);

[DllImport("user32.dll")]
public static extern bool GetCursorPos(out Point lpPoint);

public static IntPtr GetWindowUnderCursor()
{
Point ptCursor = new Point();

if (!(PInvoke.GetCursorPos(out ptCursor)))
return IntPtr.Zero;

return WindowFromPoint(ptCursor);
}

Tags What's this?: Add a tag
Flag as ContentBug
VB.net syntax      dmex   |   Edit   |   Show History
<DllImport("user32.dll", EntryPoint:="WindowFromPoint", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function WindowFromPoint(ByVal pt As POINTSTRUCT) As IntPtr End Function
Flag as ContentBug
C# syntax      dmex   |   Edit   |   Show History
[DllImport("user32.dll", EntryPoint="WindowFromPoint", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr WindowFromPoint(POINTSTRUCT pt);
Tags What's this?: c# (x) syntax (x) Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker