Exemplo n.º 1
0
 public static void MoveWindow(IntPtr hwnd, int xOffset, int yOffset)
 {
     if (hwnd != IntPtr.Zero)
     {
         WinApiManager.RECT rect = new WinApiManager.RECT();
         WinApiManager.GetWindowRect(hwnd, out rect);
         int width  = Math.Abs(rect.Right - rect.Left);
         int height = Math.Abs(rect.Bottom - rect.Top);
         int x      = Math.Max(0 - width / 2, Math.Min((int)WindowsHandler.GetScreenWidth() + width / 2, rect.Left + xOffset));
         int y      = Math.Max(0, Math.Min((int)WindowsHandler.GetScreenHeight(), rect.Top + yOffset));
         WinApiManager.SetWindowPos(hwnd, IntPtr.Zero, x, y, 0, 0, WinApiManager.SWP_NOSIZE | WinApiManager.SWP_NOACTIVATE | WinApiManager.SWP_NOZORDER | WinApiManager.SWP_SHOWWINDOW);
     }
 }
Exemplo n.º 2
0
 public static void ScaleWindow(IntPtr hwnd, double xRatio, double yRatio)
 {
     if (hwnd != IntPtr.Zero)
     {
         WinApiManager.RECT rect = new WinApiManager.RECT();
         WinApiManager.GetWindowRect(hwnd, out rect);
         int width   = Math.Abs(rect.Right - rect.Left);
         int height  = Math.Abs(rect.Bottom - rect.Top);
         int x       = rect.Left;
         int y       = rect.Top;
         int cx      = x + width / 2;
         int cy      = y + height / 2;
         int nWidth  = (int)((double)width * xRatio);
         int nHeight = (int)((double)height * yRatio);
         int nx      = cx - nWidth / 2;
         int ny      = cy - nHeight / 2;
         WinApiManager.SetWindowPos(hwnd, IntPtr.Zero, x, y, nWidth, nHeight, WinApiManager.SWP_NOACTIVATE | WinApiManager.SWP_NOZORDER | WinApiManager.SWP_SHOWWINDOW);
     }
 }