Reputation: 909
I wrote the easy test program by C# and .NET 4.0.
[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(int xPoint, int yPoint);
Point pt = MousePosition;
IntPtr w = WindowFromPoint(pt.X, pt.Y);
If this builts as 32bit, it works. But if it builds as 64bit, an unrelated window handle will return. Are there a solution or alternatives?
Upvotes: 2
Views: 3441
Reputation: 1
this is worked for me:
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(System.Drawing.Point pt);
and to use:
IntPtr hwnd = WindowFromPoint(new System.Drawing.Point(x, y));
the main document also said that we should never use the System.Window.Point
we should use System.Drawing.Point.
http://pinvoke.net/default.aspx/user32.WindowFromPoint
Upvotes: 0
Reputation: 941635
Right, that won't work. WindowFromPoint() does not take two arguments, it only takes one. A structure of type POINT. You got away with it in 32-bit code by sheer accident, that luck ran out in 64-bit mode since it passes arguments a different way.
Use the pinvoke.net web site to find the correct pinvoke declaration.
Upvotes: 11