static void ComputeRectRelativeToParent(IntPtr hWnd, IntPtr hwndParent, out PInvoke.RECT clientParent, out PInvoke.RECT client) { PInvoke.RECT rw, rc; PInvoke.GetWindowRect(hWnd, out rw); PInvoke.GetClientRect(hWnd, out rc); PInvoke.RECT rpw, rpc; PInvoke.GetWindowRect(hwndParent, out rpw); PInvoke.GetClientRect(hwndParent, out rpc); PInvoke.POINT p0 = new PInvoke.POINT() { X = rw.Left, Y = rw.Top }; PInvoke.ScreenToClient(hwndParent, ref p0); PInvoke.POINT p1 = new PInvoke.POINT() { X = rw.Right, Y = rw.Bottom }; PInvoke.ScreenToClient(hwndParent, ref p1); clientParent = rpc; client = new PInvoke.RECT() { Left = p0.X, Top = p0.Y, Right = p1.X, Bottom = p1.Y }; }
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); }