Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

WindowFromPoint (user32)
 
.
Summary

C# Signature:

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

[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(int xPoint, int yPoint);

VB.NET Signature:

<DllImport("user32.dll")> _
Private Shared Function WindowFromPoint(ByVal Point As POINT) As IntPtr
End Function

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 IntPtr WindowFromPoint(int xPoint, int yPoint);

[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);
   IntPtr hWnd = WindowFromPoint(Cursor.Position.X, Cursor.Position.Y);
   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.

Known Issue

WindowFromPoint API is unable to return correct window handle under 64bit Application Process, if any body has done it..please post.

Windows7 (vs2010)

- IntPtr WindowFromPoint(POINT Point) always return 0 in both 32/64 bit process.

- IntPtr WindowFromPoint(int x, int y) works in 32-bit but fails in 64-bit process.

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

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions