/// <summary> /// 限制鼠标在屏幕上的一个区域内 /// </summary> /// <param name="rect">限制区域</param> public static void Look(Rectangle rect) { LPRECT lpRect = new LPRECT() { Left = rect.Left, Top = rect.Top, Right = rect.Right, Bottom = rect.Bottom }; if (ClipCursor(ref lpRect) == false) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
/// <summary> /// 获取限制鼠标的区域(若无限制则返回屏幕区域) /// </summary> /// <returns>限制鼠标的区域</returns> public static Rectangle GetLockRect() { LPRECT lpRect = new LPRECT(); if (GetClipCursor(ref lpRect) == false) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return new Rectangle(lpRect.Left, lpRect.Top, lpRect.Right - lpRect.Left, lpRect.Bottom - lpRect.Top); }
private static extern bool GetClientRect(IntPtr hwnd, out LPRECT lpRect);
private static extern bool GetWindowRect(IntPtr hWnd, out LPRECT lpRect);
private static extern bool GetWindowRect(IntPtr hWnd, ref LPRECT rect);
internal static extern int GetWindowRect(System.IntPtr hWnd, ref LPRECT lpRect);
public static extern bool RedrawWindow(IntPtr hwnd, ref LPRECT rcUpdate, IntPtr hrgnUpdate, int flags);
public static extern bool InvalidateRect(IntPtr hWnd, ref LPRECT lpRect, bool bErase);
[DllImport("user32.dll")]//获得句柄对象的位置 public static extern bool GetWindowRect(IntPtr hWnd, out LPRECT lpRect);
private static extern bool GetClipCursor(ref LPRECT lpRect);