- //
- // NOTE: This is not a problem if we move the window back to (0,0)
- // because when we resize the screen buffer, the window will move back
- // to where the cursor is. Or, if the screen buffer is not resized,
- // when we readjust again the window, we will move back to a correct
- // position. This is what we wanted after all...
- //
-
- ConRect.Left = ConRect.Top = 0;
- ConRect.Right = ConRect.Left + min(oldWidth , Resolution->X) - 1;
- ConRect.Bottom = ConRect.Top + min(oldHeight, Resolution->Y) - 1;
-
- Success = SetConsoleWindowInfo(hConOut, TRUE, &ConRect);
- if (!Success) wprintf(L"(resize) SetConsoleWindowInfo(1) failed with error %d\n", GetLastError());
- }
+ Width = pcsbi->srWindow.Right - pcsbi->srWindow.Left + 1;
+ Height = pcsbi->srWindow.Bottom - pcsbi->srWindow.Top + 1;
+
+ /*
+ * If the current console window is too large for
+ * the new screen buffer, resize it first.
+ */
+ if (Width > Resolution.X || Height > Resolution.Y)
+ {
+ /*
+ * NOTE: This is not a problem if we move the window back to (0,0)
+ * because when we resize the screen buffer, the window will move back
+ * to where the cursor is. Or, if the screen buffer is not resized,
+ * when we readjust again the window, we will move back to a correct
+ * position. This is what we wanted after all...
+ */
+ ConRect.Left = ConRect.Top = 0;
+ ConRect.Right = ConRect.Left + min(Width , Resolution.X) - 1;
+ ConRect.Bottom = ConRect.Top + min(Height, Resolution.Y) - 1;
+
+ Success = SetConsoleWindowInfo(hConOut, TRUE, &ConRect);
+ if (!Success) return FALSE;
+ }