Windows命令行下实现带颜色输出
2013-05-28 16:38
204 查看
改变下一个输出或者输入字体和背景的颜色 采用SetConsoleTextAttribute函数,如 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 Gray:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |BACKGROUND_INTENSITY);
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);等等。
需要引入头文件: windows.h 函数原型:
BOOL SetConsoleTextAttribute(HANDLE hConsoleOutput, WORD wAttributes); wAttributes 的取值含义对应如下:
Attribute Meaning foreground_blue Text color contains blue.foreground_green Text color contains green.foreground_red Text color contains red. foreground_intensity Text color is intensified. background_blue Background color contains blue. background_green Background color contains green. background_red Background color contains red. background_intensity Background color is intensified. common_lvb_leading_byte Leading byte. common_lvb_trailing_byte Trailing byte. common_lvb_grid_horizontal Top horizontal. common_lvb_grid_lvertical Left vertical. common_lvb_grid_rvertical Right vertical.
common_lvb_reverse_video Reverse foreground and background attributes. common_lvb_underscore Underscore.
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 Gray:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |BACKGROUND_INTENSITY);
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);等等。
需要引入头文件: windows.h 函数原型:
BOOL SetConsoleTextAttribute(HANDLE hConsoleOutput, WORD wAttributes); wAttributes 的取值含义对应如下:
Attribute Meaning foreground_blue Text color contains blue.foreground_green Text color contains green.foreground_red Text color contains red. foreground_intensity Text color is intensified. background_blue Background color contains blue. background_green Background color contains green. background_red Background color contains red. background_intensity Background color is intensified. common_lvb_leading_byte Leading byte. common_lvb_trailing_byte Trailing byte. common_lvb_grid_horizontal Top horizontal. common_lvb_grid_lvertical Left vertical. common_lvb_grid_rvertical Right vertical.
common_lvb_reverse_video Reverse foreground and background attributes. common_lvb_underscore Underscore.
相关文章推荐
- Windows命令行下实现带颜色输出
- windows带颜色的命令行输出
- 【转】Python实现修改Windows CMD命令行输出颜色(完全解析)
- Python实现修改Windows CMD命令行输出颜色(实例解析)
- Python 命令行输出的颜色设置
- Linux终端程序用c语言实现改变输出的字的颜色 (转)
- bat_使用简单的命令行语句实现输出文件的树形目录
- 在linux命令行输出颜色
- 如何在Windows下实现将System.out输出到指定日志文件
- 【python】命令行输出颜色
- [命令行] 配置颜色(windows cmd,powershell,linux console)
- Python在windows命令行下输出彩色文字
- 在Windows中实现sudo命令——命令行环境中获取管理员权限
- Python在Linux | Windows中输出带颜色的文字的方法
- Linux终端程序用c语言实现改变输出的字的颜色
- Python实现获取命令行输出结果的方法
- Python3改变cmd(命令行)输出颜色
- NodeJS用递归实现异步操作的链式调用,完成一个简易的命令行输入输出REPL交互接口
- Python在Windows环境下命令行中使用UTF-8编码输出乱码解决
- Python脚本获取Windows窗口标题,输出到命令行