outputting Strings in the Console
#include <windows.h>
Class Console {
Public
Enum Fore_color {
F_black = 0,
F_white = Foreground_intensity | foreground_red | Foreground_green | Foreground_blue,
f_red = Foreground_intensity | Foreground_red,
F_green = Foreground_intensity | Foreground_green,
F_yellow = Foreground_intensity | foreground_red | Foreground_green,
F_blue = Foreground_intensity | Foreground_blue,
F_magenta= foreground_intensity | foreground_red | Foreground_blue,
F_cyan = Foreground_intensity | Foreground_green | Foreground_blue,
};
Enum Back_color {
B_black = 0,
B_white = Background_intensity | background_red | Background_green | Background_blue,
b_red = Background_intensity | Background_red,
B_green = Background_intensity | Background_green,
B_yellow = Background_intensity | background_red | Background_green,
B_blue = Background_intensity | Background_blue,
B_magenta= background_intensity | background_red | Background_blue,
B_cyan = Background_intensity | Background_green | Background_blue,
};
void Move (int x, int y);
void Color (Fore_color FG, Back_color BG);
void Cls (Back_color bg=b_black);
};
void Console::cls (Back_color bg) {
COORD Coordscreen = {0, 0};
DWORD Ccharswritten;
Console_screen_buffer_info Csbi;
DWORD dwconsize;
HANDLE hconsole = GetStdHandle (Std_output_handle);
Setconsoletextattribute (hconsole, BG);
Getconsolescreenbufferinfo (Hconsole, &CSBI);
Dwconsize = csbi.dwsize.x * CSBI.DWSIZE.Y;
Fillconsoleoutputcharacter (Hconsole, TEXT ("),
Dwconsize,
Coordscreen,
&ccharswritten);
Getconsolescreenbufferinfo (Hconsole, &CSBI);
Fillconsoleoutputattribute (Hconsole,
Csbi.wattributes,
Dwconsize,
Coordscreen,
&ccharswritten);
SetConsoleCursorPosition (Hconsole, Coordscreen);
}
void Console::move (int x, int y) {
COORD Point;
Point. x = x; Point. y = y;
SetConsoleCursorPosition (
GetStdHandle (Std_output_handle), point);
}
void Console::color (Fore_color FG, Back_color BG) {
Setconsoletextattribute (
GetStdHandle (Std_output_handle), FG | BG);
}
#include <iostream>
using namespace Std;
int main (int argc, char* argv[]) {
Console C;
C.cls (Console::b_green);
C.color (console::f_red, Console::b_blue);
C.move (bis);
cout << "xxx";
C.color (Console::f_blue, Console::b_yellow);
C.move (4,5);
cout << "yyyyy";
return 0;
}
outputting Strings in the Console