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
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
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

<DllImport("user32.dll")> _
Private Shared Function WindowFromPoint(ByVal xPoint As Integer, ByVal yPoint As Integer) As IntPtr
End Function

Oxygene.NET Signature:

[DllImport("user32.dll")]
class method WindowFromPoint(aPoint: System.Drawing.Point): IntPtr; external;

VB Signature:

Public Declare Function WindowFromPoint Lib "user32" _
         (ByVal Point As POINT) As Long

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.

Had the issues described below but found a way that worked for me:

WindowFromPoint(POINT Point) always returned 0 in both 32/64 bit process when I used long(Int64) for x and y in POINT struct.

When I use int(Int32) it works fine !

struct POINT {

   int x;
   int y;

}

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)

Sample code Windows 8.1 64bit

VB.net express edition 2013

Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Int32, ByVal yPoint As Int32) As Long

Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown

  Dim pntX As Int32 = MousePosition.X
  Dim pntY As Int32 = MousePosition.Y

  Dim lhWnd As Long
  lhWnd = WindowFromPoint(pntX, pntY)
  Label1.Text = lhWnd.ToString

End Sub

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
Edit This Page
Find References
Show Printable Version
Revisions