/// <summary> /// Auto detects the window under the mouse cursor. /// </summary> private void AutoDetectWindow() { this.Visible = false; Rectangle rect = Rectangle.Empty; try { try { // Wait to make sure the context menu gets closed and the drape gets invisible MainForm.SleepAndWait(10); // Get the bounds of the window under cursor rect = WinAPIHelper.RectangleFromPoint(Cursor.Position.X, Cursor.Position.Y); } catch { // ignore errors } } finally { this.Visible = true; } // Add the new auto detected focus area, if not empty and not too large if ((!rect.IsEmpty) && (!FocusControl.IsTooLarge(rect, this))) { this.AddNewFocusArea(rect); } }
/// <summary> /// Auto detects the area under the mouse cursor. /// </summary> private void AutoDetectArea() { this.Visible = false; Rectangle rect = Rectangle.Empty; try { try { // Wait to make sure the context menu gets closed and the drape gets invisible MainForm.SleepAndWait(10); // Get the bounds of the control under cursor using Accessible Objects rect = WinAPIHelper.GetAccessibleObjectBounds(Cursor.Position.X, Cursor.Position.Y); } catch { // ignore errors } // If we fail to get the bounds, or the area is too large, retry using Window methods if (rect.IsEmpty || FocusControl.IsTooLarge(rect, this)) { try { rect = WinAPIHelper.RectangleFromPoint(Cursor.Position.X, Cursor.Position.Y); } catch { // ignore errors } } } finally { this.Visible = true; } // Add the new auto detected focus area, if not empty and not too large if ((!rect.IsEmpty) && (!FocusControl.IsTooLarge(rect, this))) { this.AddNewFocusArea(rect); } }