Пример #1
0
        public static bool ElementVisibleOnScreen(IntPtr hWnd)
        {
            IntPtr hdc = PInvoke.GetDC(hWnd);

            PInvoke.RECT r;
            var          cb   = PInvoke.GetClipBox(hdc, out r);
            var          flag = false;

            switch ((PInvoke.ClipBoxComplexity)cb)
            {
            case PInvoke.ClipBoxComplexity.NullRegion:
                Console.WriteLine("window covered completely");
                flag = false;
                break;

            case PInvoke.ClipBoxComplexity.Error:
                Console.WriteLine("error: {0]", Marshal.GetLastWin32Error());
                flag = false;
                break;

            case PInvoke.ClipBoxComplexity.SimpleRegion:
                PInvoke.RECT rcClient;
                PInvoke.GetClientRect(hWnd, out rcClient);
                if (rcClient.Left == r.Left && rcClient.Top == r.Top && rcClient.Right == r.Right && rcClient.Bottom == r.Bottom)
                {
                    Console.WriteLine("completely uncovered");
                    flag = true;
                }
                else
                {
                    Console.WriteLine("partially covered");
                    flag = false;
                }
                break;

            case PInvoke.ClipBoxComplexity.ComplexRegion:
                Console.WriteLine("partially covered");
                flag = false;
                break;

            default:
                Console.WriteLine("unknown return code {0}", cb);
                flag = false;
                break;
            }
            PInvoke.ReleaseDC(hWnd, hdc);
            return(flag);
        }