SetConsoleScreenBufferInfoEx isn't working well on Window Terminal. #19082

Open
opened 2026-01-31 06:33:17 +00:00 by claunia · 0 comments
Owner

Originally created by @BDisp on GitHub (Dec 15, 2022).

Windows Terminal version

1.15.3466.0

Windows build number

10.0.22621.963

Other Software

No response

Steps to reproduce

Please try to run this code:

#include <windows.h>
#include <stdio.h>

int main(void)
{
	HANDLE hStdout;
	CONSOLE_SCREEN_BUFFER_INFOEX csbiInfoEx{ 0 };
	csbiInfoEx.cbSize = sizeof(csbiInfoEx);
	SMALL_RECT winRect, srctScrollRect, srctClipRect;
	CHAR_INFO chiFill;
	COORD coordDest;
	COORD size = COORD{ 80, 25 };
	int i;

	printf("\nPrinting 20 lines for reference. ");
	printf("Notice that line 6 is discarded during scrolling.\n");
	for (i = 0; i <= 20; i++)
		printf("%d\n", i);

	hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

	if (hStdout == INVALID_HANDLE_VALUE)
	{
		printf("GetStdHandle failed with %d\n", GetLastError());
		return 1;
	}

	// Get the screen buffer size. 

	if (!GetConsoleScreenBufferInfoEx(hStdout, &csbiInfoEx))
	{
		printf("GetConsoleScreenBufferInfoEx failed %d\n", GetLastError());
		return 1;
	}

	// Set the screen buffer size. 

	csbiInfoEx.dwSize = size;
	csbiInfoEx.srWindow = SMALL_RECT{ 0,0,size.X,size.Y };
	csbiInfoEx.dwMaximumWindowSize = size;

	if (!SetConsoleScreenBufferInfoEx(hStdout, &csbiInfoEx))
	{
		printf("SetConsoleScreenBufferInfoEx failed %d\n", GetLastError());
		return 1;
	}

	// Set the screen size. 

	winRect = { 0,0,(short)(size.X - 1),(short)(size.Y - 1) };

	if (!SetConsoleWindowInfo(hStdout, true, &winRect))
	{
		printf("SetConsoleWindowInfo failed %d\n", GetLastError());
		return 1;
	}

	// The scrolling rectangle is the bottom 15 rows of the 
	// screen buffer. 

	srctScrollRect.Top = csbiInfoEx.dwSize.Y - 16;
	srctScrollRect.Bottom = csbiInfoEx.dwSize.Y - 1;
	srctScrollRect.Left = 0;
	srctScrollRect.Right = csbiInfoEx.dwSize.X - 1;

	// The destination for the scroll rectangle is one row up. 

	coordDest.X = 0;
	coordDest.Y = csbiInfoEx.dwSize.Y - 17;

	// The clipping rectangle is the same as the scrolling rectangle. 
	// The destination row is left unchanged. 

	srctClipRect = srctScrollRect;

	// Fill the bottom row with green blanks. 

	chiFill.Attributes = BACKGROUND_GREEN | FOREGROUND_RED;
	chiFill.Char.UnicodeChar = ' ';

	// Scroll up one line. 

	if (!ScrollConsoleScreenBuffer(
		hStdout,         // screen buffer handle 
		&srctScrollRect, // scrolling rectangle 
		&srctClipRect,   // clipping rectangle 
		coordDest,       // top left destination cell 
		&chiFill))       // fill character and color
	{
		printf("ScrollConsoleScreenBuffer failed %d\n", GetLastError());
		return 1;
	}

	(void)getchar(); //Explicitly ignore return value.

	return 0;
}

Expected Behavior

With Windows Console Host I get the right size:

imagem

Actual Behavior

With Windows Terminal I don't get the right size screen as expected. See the point missing after the word scrolling.
Look at the green blanks filled at the bottom which occupies all the incorrect console size.
If I'm doing something wrong, please let me know. Thanks.

imagem

Originally created by @BDisp on GitHub (Dec 15, 2022). ### Windows Terminal version 1.15.3466.0 ### Windows build number 10.0.22621.963 ### Other Software _No response_ ### Steps to reproduce Please try to run this code: ```c++ #include <windows.h> #include <stdio.h> int main(void) { HANDLE hStdout; CONSOLE_SCREEN_BUFFER_INFOEX csbiInfoEx{ 0 }; csbiInfoEx.cbSize = sizeof(csbiInfoEx); SMALL_RECT winRect, srctScrollRect, srctClipRect; CHAR_INFO chiFill; COORD coordDest; COORD size = COORD{ 80, 25 }; int i; printf("\nPrinting 20 lines for reference. "); printf("Notice that line 6 is discarded during scrolling.\n"); for (i = 0; i <= 20; i++) printf("%d\n", i); hStdout = GetStdHandle(STD_OUTPUT_HANDLE); if (hStdout == INVALID_HANDLE_VALUE) { printf("GetStdHandle failed with %d\n", GetLastError()); return 1; } // Get the screen buffer size. if (!GetConsoleScreenBufferInfoEx(hStdout, &csbiInfoEx)) { printf("GetConsoleScreenBufferInfoEx failed %d\n", GetLastError()); return 1; } // Set the screen buffer size. csbiInfoEx.dwSize = size; csbiInfoEx.srWindow = SMALL_RECT{ 0,0,size.X,size.Y }; csbiInfoEx.dwMaximumWindowSize = size; if (!SetConsoleScreenBufferInfoEx(hStdout, &csbiInfoEx)) { printf("SetConsoleScreenBufferInfoEx failed %d\n", GetLastError()); return 1; } // Set the screen size. winRect = { 0,0,(short)(size.X - 1),(short)(size.Y - 1) }; if (!SetConsoleWindowInfo(hStdout, true, &winRect)) { printf("SetConsoleWindowInfo failed %d\n", GetLastError()); return 1; } // The scrolling rectangle is the bottom 15 rows of the // screen buffer. srctScrollRect.Top = csbiInfoEx.dwSize.Y - 16; srctScrollRect.Bottom = csbiInfoEx.dwSize.Y - 1; srctScrollRect.Left = 0; srctScrollRect.Right = csbiInfoEx.dwSize.X - 1; // The destination for the scroll rectangle is one row up. coordDest.X = 0; coordDest.Y = csbiInfoEx.dwSize.Y - 17; // The clipping rectangle is the same as the scrolling rectangle. // The destination row is left unchanged. srctClipRect = srctScrollRect; // Fill the bottom row with green blanks. chiFill.Attributes = BACKGROUND_GREEN | FOREGROUND_RED; chiFill.Char.UnicodeChar = ' '; // Scroll up one line. if (!ScrollConsoleScreenBuffer( hStdout, // screen buffer handle &srctScrollRect, // scrolling rectangle &srctClipRect, // clipping rectangle coordDest, // top left destination cell &chiFill)) // fill character and color { printf("ScrollConsoleScreenBuffer failed %d\n", GetLastError()); return 1; } (void)getchar(); //Explicitly ignore return value. return 0; } ``` ### Expected Behavior With `Windows Console Host` I get the right size: ![imagem](https://user-images.githubusercontent.com/13117724/207921245-1becac6c-5b55-4096-99a1-ef4de117fd45.png) ### Actual Behavior With `Windows Terminal` I don't get the right size screen as expected. See the point missing after the word `scrolling.` Look at the green blanks filled at the bottom which occupies all the incorrect console size. If I'm doing something wrong, please let me know. Thanks. ![imagem](https://user-images.githubusercontent.com/13117724/207922403-87e6c2ab-4417-415e-8d6e-4f3ae906e68d.png)
claunia added the Issue-BugResolution-Duplicate labels 2026-01-31 06:33:17 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19082