public static WindowAtPosition ( int px, int py ) : |
||
px | int | |
py | int | |
return |
public static IntPtr WindowAtPosition (int px, int py)
{
var startHandle = IntPtr.Zero;
var topWin = TopWindowAtPosition (px, py);
if (topWin != null)
startHandle = GetWindowHandle (topWin);
if (startHandle == IntPtr.Zero)
startHandle = RootWindowHandle;
return ChildWindowAtPosition (startHandle, px, py, false);
}
public static AutomationElement FromPoint(Point pt) { IntPtr handle = NativeMethods.WindowAtPosition((int)pt.X, (int)pt.Y); if (handle == IntPtr.Zero) { return(RootElement); } AutomationElement startElement = null; try { startElement = FromHandle(handle); } catch (ElementNotAvailableException) { return(RootElement); } if (startElement == RootElement) { return(RootElement); } //Keep searching the descendant element which are not native window var sourceElement = startElement.SourceElement. GetDescendantFromPoint(pt.X, pt.Y); return(SourceManager.GetOrCreateAutomationElement(sourceElement)); }