// test.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include#include 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