我正在尝试在 cmd 屏幕上绘制一个棋盘 - 64 个正方形,每个正方形中有一个字母,象征着这个地方的士兵。 经过很长时间的搜索,我找到了一个改变单词颜色的代码,但我的问题是如何在 cmd 上绘制正方形?黑色 - 白色等等。 这是我找到的代码:
int main()
{
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// Use the three primary colors for mixing any other color.
// Use FOREGROUND_INTENSITY for brighter colors.
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
cout << "Bright red text\n";
SetConsoleTextAttribute
(hConsole, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout << "Bright blue text\n";
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout << "Back to normal white text\n";
// Wait for user pressing key before exiting
// Gives them a chance to see the output
cout << "\n\nPress any key to exit program.....";
cin.get();
return 0;
}
我很乐意提供一些帮助。
最佳答案
因为白色是红+绿+蓝:背景白色是
BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE
在代码中:
SetConsoleTextAttribute
(hConsole,BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE )
cout << "black on white\n";
关于c++ - 使用 C++ 在 cmd 上绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27666641/