WindowFromPoint (user32)
Last changed: -98.115.156.13

.
Summary

C# Signature:

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

User-Defined Types:

POINT

Notes:

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

Tips & Tricks:

Please add some!

Sample Code:

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

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

[DllImport("user32.dll")]
static extern bool SetWindowText(IntPtr hWnd, string lpString);

Point p;
if (GetCursorPos(out p))
{
   IntPtr hWnd = WindowFromPoint(p);
   SetWindowText(hWnd, "Window Found");
}

Alternative Managed API:

Do you know one? Please contribute it!

VB Signature:

Imports System.Runtime.InteropServices
Module test
<DllImport("user32.dll")> _
Function WindowFromPoint(ByVal xyPoint As POINT) As Long
End Function
end module

User-Defined Types:

xPoint, yPoint

Notes:

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

Tips & Tricks:

Please add some!

Sample Code:

Dim tPA As Point
Dim lhWnd As Long
tPA = Cursor.Position
' Get window handle from point
lhWnd = WindowFromPoint(tPA)

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/windowfrompoint.asp