/// <summary> /// Captures the specified window from the screen including any overlapped windows. /// </summary> /// <param name="hWnd">The handle of the window to capture</param> /// <param name="clientArea">If only the client area (non-chrome area) should be captured.</param> /// <returns>An image with the window drawn on it</returns> public static Bitmap Capture(IntPtr hWnd, bool clientArea) { Native.Internal.NativeStructs.RECT r = new Native.Internal.NativeStructs.RECT(); if (clientArea) { Native.Internal.NativeMethods.GetClientRect(hWnd, ref r); Point pt = Point.Empty.ClientToScreen(hWnd, false); r = new Rectangle(pt, ((Rectangle)r).Size); } else { Native.Internal.NativeMethods.GetWindowRect(hWnd, ref r); } return(Capture(r)); }
/// <summary> /// Captures the specified window from the screen including any overlapped windows. /// </summary> /// <param name="hWnd">The handle of the window to capture</param> /// <param name="clientArea">If only the client area (non-chrome area) should be captured.</param> /// <returns>An image with the window drawn on it</returns> public static Bitmap Capture(IntPtr hWnd, bool clientArea) { Native.Internal.NativeStructs.RECT r = new Native.Internal.NativeStructs.RECT(); if (clientArea) { Native.Internal.NativeMethods.GetClientRect(hWnd, ref r); Point pt = Point.Empty.ClientToScreen(hWnd, false); r = new Rectangle(pt, ((Rectangle)r).Size); } else { Native.Internal.NativeMethods.GetWindowRect(hWnd, ref r); } return Capture(r); }
public static Point ClientToScreen(this Point pt, IntPtr hWnd, bool includesFrame) { Point p = pt; NativeMethods.ClientToScreen(hWnd, ref p); if (!includesFrame) { return p; } Native.Internal.NativeStructs.RECT r = new Native.Internal.NativeStructs.RECT(); NativeMethods.GetWindowRect(hWnd, ref r); Rectangle rect = r; NativeMethods.GetClientRect(hWnd, ref r); pt = Point.Empty.ClientToScreen(hWnd, false); Rectangle client = new Rectangle(pt, ((Rectangle)r).Size); int titleHeight = client.Top - rect.Top; return new Point(p.X - (client.Width - rect.Width) / 2, p.Y - titleHeight); }
public static Point ClientToScreen(this Point pt, IntPtr hWnd, bool includesFrame) { Point p = pt; NativeMethods.ClientToScreen(hWnd, ref p); if (!includesFrame) { return(p); } Native.Internal.NativeStructs.RECT r = new Native.Internal.NativeStructs.RECT(); NativeMethods.GetWindowRect(hWnd, ref r); Rectangle rect = r; NativeMethods.GetClientRect(hWnd, ref r); pt = Point.Empty.ClientToScreen(hWnd, false); Rectangle client = new Rectangle(pt, ((Rectangle)r).Size); int titleHeight = client.Top - rect.Top; return(new Point(p.X - (client.Width - rect.Width) / 2, p.Y - titleHeight)); }