Exemplo n.º 1
0
        public bool IsOverlapped()
        {
            if (_blurValues.BlurWhenFocusLost ||
                !PI.IsWindowVisible(_parentForm.Handle)
                )
            {
                return(false);
            }

            IntPtr hWnd = _parentForm.Handle;
            // The set is used to make calling GetWindow in a loop stable by checking if we have already
            //  visited the window returned by GetWindow. This avoids the possibility of an infinite loop.
            var visited = new HashSet <IntPtr> {
                hWnd
            };

            try
            {
                Form activeForm = Form.ActiveForm;
                if (activeForm != null)
                {
                    visited.Add(activeForm.Handle);
                }

                visited.Add(_visualBlur.Handle);


                PI.RECT thisRect = new();
                PI.GetWindowRect(hWnd, ref thisRect);

                while ((hWnd = PI.GetWindow(hWnd, PI.GetWindowType.GW_HWNDPREV)) != IntPtr.Zero &&
                       !visited.Contains(hWnd))
                {
                    visited.Add(hWnd);
                    PI.RECT testRect = new();
                    if (PI.IsWindowVisible(hWnd) &&
                        PI.GetWindowRect(hWnd, ref testRect) &&
                        PI.IntersectRect(out _, ref thisRect, ref testRect)
                        )
                    {
                        return(true);
                    }
                }

                return(false);
            }
            finally
            {
                // Attempt to clear sooner to allow handles to be released.
                visited.Clear();
                visited = null;
            }
        }