internal static void RestoreOriginalPosition()
 {
     User32Wrapper.SetWindowPos(
         _hWndActive.Value,
         0,
         _rect.Value.Left,
         _rect.Value.Top,
         _rect.Value.Right - _rect.Value.Left,
         _rect.Value.Bottom - _rect.Value.Top,
         SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE);
 }
        public static void TransformWindow(TranslateWindowCommand direction, int rows, int cols)
        {
            if (_hWndActive == null)
            {
                throw new Exception("Error: ForegroundWindow not initialized!");
            }

            Object obj = new object();

            if (!User32Wrapper.GetWindowRect(new HandleRef(obj, _hWndActive.Value), out User32Wrapper.RECT rect))
            {
                Console.WriteLine("Error: Cannot get window dimensions.");
                return;
            }

            if (direction == TranslateWindowCommand.Minimize)
            {
                if (User32Wrapper.IsWindowVisible(_hWndActive.Value))
                {
                    User32Wrapper.MinimizeWindow(_hWndActive.Value);
                }
                else
                {
                    User32Wrapper.NormalizeWindow(_hWndActive.Value);
                }
            }
            else if (direction == TranslateWindowCommand.Maximize)
            {
                User32Wrapper.MaximizeWindow(_hWndActive.Value);
            }
            else
            {
                User32Wrapper.NormalizeWindow(_hWndActive.Value);

                int x      = rect.Left;
                int width  = rect.Right - rect.Left;
                int y      = rect.Top;
                int height = rect.Bottom - rect.Top;

                int offset = CalculateOffsetToClosestStop(rows, cols, x, y, width, height, direction);
                if (offset == -1)
                {
                    return;
                }

                switch (direction)
                {
                case TranslateWindowCommand.MoveUp:
                    y = y - offset;
                    break;

                case TranslateWindowCommand.MoveDown:
                    y = y + offset;
                    break;

                case TranslateWindowCommand.MoveLeft:
                    x = x - offset;
                    break;

                case TranslateWindowCommand.MoveRight:
                    x = x + offset;
                    break;

                case TranslateWindowCommand.MoveTopUp:
                    y      = y - offset;
                    height = height + offset;
                    break;

                case TranslateWindowCommand.MoveTopDown:
                    y      = y + offset;
                    height = height - offset;
                    break;

                case TranslateWindowCommand.MoveBottomUp:
                    height = height - offset;
                    break;

                case TranslateWindowCommand.MoveBottomDown:
                    height = height + offset;
                    break;

                case TranslateWindowCommand.MoveLeftLeft:
                    x     = x - offset;
                    width = width + offset;
                    break;

                case TranslateWindowCommand.MoveLeftRight:
                    x     = x + offset;
                    width = width - offset;
                    break;

                case TranslateWindowCommand.MoveRightLeft:
                    width = width - offset;
                    break;

                case TranslateWindowCommand.MoveRightRight:
                    width = width + offset;
                    break;
                }

                User32Wrapper.SetWindowPos(_hWndActive.Value, 0, x, y, width, height, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE);
            }
        }