From 6ae47b744e569b8bc9b71d02cac88bfbd3f594f8 Mon Sep 17 00:00:00 2001 From: Amos Date: Tue, 4 Jul 2023 18:32:35 +0200 Subject: [PATCH] Fix console window shrinking with 1 unit This commit fixes an issue where the console window would shrink with 1 unit when calling 'SetConsoleBackgroundColor'. The bottom should be incremented by 1 each time its getting called, as it appears to be decremented again in WINAPI 'SetConsoleScreenBufferInfoEx'. --- r5dev/windows/console.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/r5dev/windows/console.cpp b/r5dev/windows/console.cpp index 05771b60..0e33f60e 100644 --- a/r5dev/windows/console.cpp +++ b/r5dev/windows/console.cpp @@ -25,12 +25,16 @@ static std::string s_ConsoleInput; //----------------------------------------------------------------------------- void SetConsoleBackgroundColor(COLORREF color) { - CONSOLE_SCREEN_BUFFER_INFOEX sbInfoEx{}; + CONSOLE_SCREEN_BUFFER_INFOEX sbInfoEx{0}; sbInfoEx.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX); HANDLE consoleOut = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfoEx(consoleOut, &sbInfoEx); + // The '+= 1' is required, else the window will shrink + // by '1' each time this function is getting called on + // the same console window. + sbInfoEx.srWindow.Bottom += 1; sbInfoEx.ColorTable[0] = color; SetConsoleScreenBufferInfoEx(consoleOut, &sbInfoEx); } @@ -43,7 +47,7 @@ void SetConsoleBackgroundColor(COLORREF color) //----------------------------------------------------------------------------- void FlashConsoleBackground(int nFlashCount, int nFlashInterval, COLORREF color) { - CONSOLE_SCREEN_BUFFER_INFOEX sbInfoEx{}; + CONSOLE_SCREEN_BUFFER_INFOEX sbInfoEx{0}; sbInfoEx.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX); HANDLE consoleOut = GetStdHandle(STD_OUTPUT_HANDLE);