cmd运行程序 改变字体与背景 (c++)(windows)

在#include <windows.h> 库里

首先知道:

0=黑色
1=蓝色
2=绿色
3=湖蓝色
4=红色
5=紫色
6=黄色
7=白色
8=灰色
9=淡蓝色
A=淡绿色
B=淡浅绿色
C=淡红色
D=淡紫色
E=淡黄色
F=亮白色
 
方法一:
常用cmd上 color 函数 (注意!!!是改变全部
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;

int main() {
	system("color 46");//第一个是背景,第二个是字体
     //这是红底黄字 return 0; }

方法二:

运用SetConsoleTextAttribute 百度翻译:集合控制台文本属性

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;

int main() {
	for (int i=0;i<8192;i++)
	{
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),i);
		printf("%x\n",i);
	}
	return 0;
}
 
据以上实验知:16进制下:
第一位:字体
第二位:背景
第三位:0~3 无
    4~7 上划线(与字体同色)
    8~b 左竖线  (与字体同色)
    c~f  左上线  (与字体同色)
    10~13 右竖线  (与字体同色)
    14~17 右上线  (与字体同色)
    18~1b 左右线  (与字体同色)
    1c~1f 左右上线  (与字体同色)
运用以上,使程序更好看!!!
 

猜你喜欢

转载自www.cnblogs.com/Srand-X/p/12122045.html