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.
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.
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.
To change the background color of text in Console, use the Console. BackgroundColor Property in C#.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With