private Image GetDesktopBitmap(IntPtr hWnd, User32.RECT rect) { var crect = new User32.RECT(rect.Left, rect.Top, rect.Right, rect.Bottom); var p = new User32.POINT(0, 0); User32.ClientToScreen(hWnd, ref p); crect.Top = p.Y; crect.Left = p.X; crect.Bottom = p.Y + crect.Bottom; crect.Right = p.X + crect.Right; if (VisibilityTester.HitTest(crect, hWnd, new[] { new Point(p.X + 1, p.Y + 1) }, IntPtr.Zero)) { return GetDesktopBitmap(hWnd); } return null; }
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, User32.SetWindowPostFlags wFlags);
public static extern bool GetClientRect(IntPtr hWnd, ref User32.RECT lpRect);
public static extern bool GetWindowRect(IntPtr hWnd, ref User32.RECT lpRect);
/// <summary> /// Activates (bring foreground) the given window. /// </summary> /// <param name="winHandle">A handle to the window</param> /// <param name="sizeFlag">How the window should be shown if minimized</param> static private void activate(IntPtr winHandle, User32.ShowState sizeFlag) { switch (sizeFlag) { case User32.ShowState.Restore: if (isMiniMized(winHandle)) User32.ShowWindow(winHandle, User32.ShowState.Normal); User32.SetForeground(winHandle); break; case User32.ShowState.Maximize: if (isMiniMized(winHandle)) User32.ShowWindow(winHandle, User32.ShowState.ShowMaximized); User32.SetForeground(winHandle); break; default: User32.ShowWindow(winHandle, sizeFlag); User32.SetForeground(winHandle); break; } }
public Monitor(IntPtr handle, User32.MonitorInfo info) { MonitorHandle = handle; MonitorInfo = info; }