/// <summary>
        /// whether the UI element contains point(x,y)
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool InRange(IntPtr hWnd, double x, double y)
        {
            try
            {
                NativeMethods.RECT clientRect = GetBoundaryRect(hWnd);

                if (clientRect.width == 0 || clientRect.height == 0)
                {
                    return(false);
                }

                double monitorScaling = 1.0d;
                var    monitor        = GetMonitor(hWnd);
                if (monitor != IntPtr.Zero)
                {
                    // Calculate monitor scaling relative to primary monitor
                    var monitorInfo          = _screenProps.GetMonitorInformation(monitor);
                    var monitorScalingFactor = monitorInfo.scalingFactor;
                    var defaultScalingFactor = _screenProps.GetMonitorInformation(IntPtr.Zero).scalingFactor;
                    monitorScaling = monitorScalingFactor / defaultScalingFactor;
                }

                if ((clientRect.left * monitorScaling <= x && x <= clientRect.right * monitorScaling) &&
                    (clientRect.top * monitorScaling <= y && y < clientRect.bottom * monitorScaling))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Diagnostics.LogException(ex);
            }
            return(false);
        }
Пример #2
0
 public ScreenProperties.MonitorInformation GetMonitorInformation(IntPtr hMonitor)
 {
     return(_screenProps.GetMonitorInformation(hMonitor));
 }