Printing text with transparent background

Hi
I'm creating a text console application. I have a function that takes a SMALL_RECT and fills the area with a given character. In my application, the background is going to be multicolored, the problem is when after changing the background color and I want to print a rectangle, I get a black background behind the text. So is there any way to tell the program to just print the text without changing the background color?

This is how I print the rectangles:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
BOOL fillArea(const SMALL_RECT* lpScrollRectangle, WCHAR c)
{
	HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	if (GetConsoleScreenBufferInfo(hConsoleOutput, &csbi))
	{
		CHAR_INFO fi = { c, csbi.wAttributes };
		if (!lpScrollRectangle)
		{
			csbi.srWindow.Left = 0;
			csbi.srWindow.Top = 0;
			csbi.srWindow.Right = csbi.dwSize.X - 1;
			csbi.srWindow.Bottom = csbi.dwSize.Y - 1;
			lpScrollRectangle = &csbi.srWindow;
		}
		return ScrollConsoleScreenBufferW(hConsoleOutput, lpScrollRectangle, 0, csbi.dwSize, &fi);
	}
	return FALSE;
}

void print(SMALL_RECT rr,WCHAR wc)
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5);
	fillArea(&rr,wc);
}


int main()
{
  //The background is already colored  

  print({5,5,10,10},'*');


  std::cin.get();
  return 0;
}


Since there are multiple colors, I don't want to waste time checking for the background color (if that's possible) on every character, I just want to passively print the text on the background, like a transparent text.

Thanks :)
Last edited on
https://docs.microsoft.com/en-us/windows/console/console-screen-buffers#_win32_font_attributes
There is no transparent, so it looks like you need to read each cell to find out what's there in order to combine it with what you want to print.
An old CPlusPlus article that might be helpful in understanding how to manipulate foreground and background colors in a Win32 console:
http://www.cplusplus.com/articles/Eyhv0pDG/
Thanks everyone for the help! I'll check this http://www.cplusplus.com/articles/Eyhv0pDG/
out later. :)
Last edited on
Topic archived. No new replies allowed.