在#include <windows.h> 库里c++
首先知道:windows
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 左右上线 (与字体同色)
运用以上,使程序更好看!!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
一样在#include <windows.h>
方法一:
使用cmd中:mode con cols=x lines=y (x是长,y是宽)
1 #include <Windows.h> 2 3 int main() { 4 system("mode con cols=100 lines=20"); 5 return 0; 6 }
方法二:spa
函数:SetWindowPos(翻译:设置窗口位置)翻译
1 #include <Windows.h> 2 3 int main() { 4 HWND hWnd = GetConsoleWindow(); //得到cmd窗口句柄 5 SetWindowPos(hWnd,NULL,1,2,100,20,NULL); 6 return 0; 7 }
(1,0):窗口左上角的位置code
(100,200) 窗口大小blog