WindowFromPoint function
Applies to: desktop apps only
Retrieves a handle to the window that contains the specified point.
Syntax
HWND WINAPI WindowFromPoint( __in POINT Point );
Parameters
- Point [in]
-
Type: POINT
The point to be checked.
Return value
Type:
Type: HWND
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.
Examples
For an example, see "Interface from Running Object Table" in About Text Object Model.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- Reference
- ChildWindowFromPoint
- Conceptual
- Windows
- Other Resources
- POINT
- WindowFromDC
Send comments about this topic to Microsoft
Build date: 2/3/2012
- 1/2/2012
- ElmueSoft
http://blogs.msdn.com/b/oldnewthing/archive/2010/12/30/10110077.aspx
"WindowFromPoint, ChildWindowFromPoint, RealChildWindowFromPoint, when will it all end?"
- 12/31/2010
- peterchen!
- 12/31/2010
- peterchen!
[DllImport("user32.dll", EntryPoint="WindowFromPoint", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr WindowFromPoint(POINTSTRUCT pt);
<DllImport("user32.dll", EntryPoint:="WindowFromPoint", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function WindowFromPoint(ByVal pt As POINTSTRUCT) As IntPtr
End Function
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);
}