vs 中怎么用c改变部分字体颜色
// test.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <windows.h> #include<conio.h> void SetColor(unsigned short ForeColor,unsigned short BackGroundColor) { HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE); WORD wr ; //这里可以自己把握 switch (BackGroundColor) { case '1': wr = FOREGROUND_INTENSITY | FOREGROUND_RED;break; case '2': wr = FOREGROUND_INTENSITY | FOREGROUND_GREEN;break; default: wr = FOREGROUND_INTENSITY | FOREGROUND_BLUE; break; } /*SetConsoleTextAttribute(hCon,(ForeColor%16)|(BackGroundColor%16*16));*/ SetConsoleTextAttribute(hCon,wr); } int _tmain(int argc, _TCHAR* argv[]) { int color; char i = '1'; /* HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED); printf("把这句话颜色变成红色\n"); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN); printf("把这句话颜色变成黄色\n"); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_BLUE); printf("把这句话颜色变成黄色\n"); system("pause");*/ for(color = 0; color < 8; color++) /*设置颜色0到15*/ { printf("No.%d\r\n", color); /*\r\n代表换行*/ system("pause"); SetColor(0,i); printf("加油,中国!!"); /*SetColor(7,0);///恢复为黑底白字。*/ i++; } return 0; }
case '1': wr = FOREGROUND_INTENSITY | FOREGROUND_RED;break; case '2': wr = FOREGROUND_INTENSITY | FOREGROUND_GREEN;break;
这里不行就改成1,2
作者:三小
声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!