Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get current console background and text colors?

I know how to set them (SetConsoleTextAttribute) but there isn't a GetConsoleTextAttribute to retrieve this information. On a unaffected console it should be int 7.

The problem is that when exiting from a program that sets the text color it stays the same for the time given window runs, and I cannot assume that user hasn't set the colors to his custom liking.

like image 501
rsk82 Avatar asked Dec 20 '11 16:12

rsk82


People also ask

How do I change my console background color?

You can set Console. BackgroundColor property to ConsoleColor enumeration.. Gets or sets the background color of the console. To change the background color of the > console window as a whole, set the BackgroundColor property and call the Clear method.

How do I change the background color of my console in C++?

In C++ programming, the default background of the output screen is black and the text color is the white color, the task is to color both the background and text color in the output screen. console_color = GetStdHandle(STD_OUTPUT_HANDLE); // P is color code according to your need.

How to change background color of text in C#?

To change the background color of text in Console, use the Console. BackgroundColor Property in C#.


1 Answers

A quick grep of wincon.h shows that CONSOLE_SCREEN_BUFFER_INFO has a wAttributes member which is documented as "The attributes of the characters written to a screen buffer by the WriteFile and WriteConsole functions, or echoed to a screen buffer by the ReadFile and ReadConsole functions." This matches the description of SetConsoleTextAttribute: "Sets the attributes of characters written to the console screen buffer by the WriteFile or WriteConsole function, or echoed by the ReadFile or ReadConsole function." The structure is returned by GetConsoleScreenBufferInfo.

like image 104
Raymond Chen Avatar answered Sep 24 '22 11:09

Raymond Chen