The simplest way to do this is to control the whole thing, and feel a little silly./(ㄒoㄒ)/~~
Note that all need header files <windows.h>
... system ("color 04"), and so on.
The first number represents the background color, and the second number represents the foreground. The codes for each color are as follows: 0 = black 1= Blue 2 = Green 3= Lake Blue 4 = Red 5 = Purple 6 = Yellow 7 = White 8 = Gray 9 = light blue a= light green b= light green c= light Red d= lavender e= light yellow f= bright white
two. Handle Control hi up O (∩_∩) o~ setconsoletextattribute functionSee a C Example:
#include <stdio.h>
#include <windows.h>
int main ()
{
HANDLE consolehwnd;//Creating a handle
Consolehwnd=getstdhandle (Std_output_handle);//Instantiate handle
Setconsoletextattribute (consolehwnd,foreground_red);//Set Font color
printf ("Hello");
Setconsoletextattribute (consolehwnd,foreground_intensity| Foreground_green);
printf ("world!\n");
GetChar ();
Setconsoletextattribute (consolehwnd,background_intensity| Background_blue);
printf ("itisreallybeautiful!\n");
return 0;
}
Foreground_red indicates that the setting foreground color is red, that is, the color of the font is red;
Foreground_intensity indicates that the foreground color is set to highlight,
Foreground_green Green, two parameters in the middle plus "|" Indicates that the foreground color is highlighted green;
Background_intensity indicates that setting the background color is highlighted,
Background_blue indicates that the background color is blue,
background_intensity | Background_blue two parameters to make the background color bright blue.
To represent a red font, a white background can be used Setconsoletextattribute (GetStdHandle (std_output_handle), background_intensity | foreground_intensity | foreground_red| background_red | Background_green | Background_blue);
Set background and font to highlighted Background_intensity | Foreground_intensity,
Set the font color to foreground_red and the background color to background_red | Background_green | Background_blue.
In fact, these values add up to binary, 11111100, that is, Hex 0xFC.
So set white body red Word can also be written as: Setconsoletextattribute (GetStdHandle (std_output_handle), 0xFC).
Other colors can take this analogy: white on Black:setconsoletextattribute (GetStdHandle (std_output_handle), foreground_intensity | foreground_red | Foreground_green | Foreground_blue);
Red on Black:setconsoletextattribute (GetStdHandle (std_output_handle), foreground_intensity | foreground_red);
Green on Black:setconsoletextattribute (GetStdHandle (std_output_handle), foreground_intensity | Foreground_green);
Yellow on Black:setconsoletextattribute (GetStdHandle (std_output_handle), foreground_intensity | foreground_red | Foreground_green);
Blue on Black:setconsoletextattribute (GetStdHandle (std_output_handle), foreground_intensity | Foreground_blue);
Magenta on Black:setconsoletextattribute (GetStdHandle (std_output_handle), foreground_intensity | foreground_red | Foreground_blue);
Cyan on Black:setconsoletextattribute (GetStdHandle (std_output_handle), foreground_intensity | Foreground_green | Foreground_blue);
Black on White:setconsoletextattribute (GetStdHandle (std_output_handle), background_intensity | foreground_intensity | background_red | Background_green | Background_blue);
Red on White:setconsoletextattribute (GetStdHandle (std_output_handle), background_intensity | foreground_intensity | background_red | Background_green | Background_blue | foreground_red);
Iii. handle control hi up O (∩_∩) o~ changes to console properties
Get Console window information Getconsolescreenbufferinfo ();
Gets the console window caption Getconsoletitle ();
Changes the specified buffer size setconsolescreenbuffersize ();
Setting the console window title setconsoletitle ();
Setting the console window information setconsolewindowinfo ();
Let's look at a c example:
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <conio.h>
#define N 255
int main ()
{
HANDLE handle_out; Define a handle
Console_screen_buffer_info SCBI; Defines a window buffer information structure body
COORD size = {80, 25}; Define a coordinate structure body
Char Strtitle[n];
Handle_out = GetStdHandle (Std_output_handle); Get standard output device handle
Getconsolescreenbufferinfo (Handle_out, &SCBI); Get window buffer Information
Getconsoletitle (Strtitle, N); Get the current window title
printf ("Current window title:%sn", strtitle);
_getch ();
Setconsoletitle ("console window operation"); Set the window title to "Console window actions"
Getconsoletitle (Strtitle, N); Get the current window title
printf ("Current window title:%sn", strtitle);
_getch ();
Setconsolescreenbuffersize (handle_out, size); Reset buffer Size
_getch ();
Small_rect rc = {0, 0, 80-1, 25-1}; Reset Window position and size
Setconsolewindowinfo (Handle_out, 1, &RC);
CloseHandle (handle_out); Turn off standard output device handles
return 0;
}
Where the Setconsolescreenbuffersize function specifies the size of the new console screen buffer, in character columns and behavior units.
The width and height specified cannot be less than the width and height of the console screen buffer window.
The specified size cannot be less than the minimum allowable size for the system.
This minimum depends on the current font size of the console (selected by the user).
In addition, the specific implementation of the Getconsoletitle function takes the form of whether the macro defines Unicode (in relation to file encoding).
The dark console can also dazzle up to 66666