outputting Strings in the Console

Source: Internet
Author: User


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, &AMP;CSBI);
Dwconsize = csbi.dwsize.x * CSBI.DWSIZE.Y;
Fillconsoleoutputcharacter (Hconsole, TEXT ("),
Dwconsize,
Coordscreen,
&ccharswritten);
Getconsolescreenbufferinfo (Hconsole, &AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.