public static void InvertScreenRect(IntPtr hwnd, Rectangle rect) { Winapi.RECT rect2; var loc = Winapi.GetWindowRect(hwnd).Location; rect.Offset(-loc.X, -loc.Y); var hdc = Winapi.GetWindowDC(hwnd); //top edge rect2 = new Winapi.RECT(rect.Left, rect.Top, rect.Right, rect.Top + INVERT_BORDER); InvertRect(hdc, ref rect2); //left edge rect2 = new Winapi.RECT(rect.Left, rect.Top + INVERT_BORDER, rect.Left + INVERT_BORDER, rect.Bottom - INVERT_BORDER); InvertRect(hdc, ref rect2); //right edge rect2 = new Winapi.RECT(rect.Right - INVERT_BORDER, rect.Top + INVERT_BORDER, rect.Right, rect.Bottom - INVERT_BORDER); InvertRect(hdc, ref rect2); //bottom edge rect2 = new Winapi.RECT(rect.Left, rect.Bottom - INVERT_BORDER, rect.Right, rect.Bottom); InvertRect(hdc, ref rect2); Winapi.ReleaseDC(hwnd, hdc); }
static extern bool OffsetRect(ref Winapi.RECT lprc, int dx, int dy);
static extern bool SetRect(out Winapi.RECT lprc, int xLeft, int yTop, int xRight, int yBottom);
static extern bool InvertRect(IntPtr hDC, [In] ref Winapi.RECT lprc);