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 :


Community Content

deodorant
C# declaration and example

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 :

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

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

Page view tracker