#include "stdafx.h" #include <windows.h> /* 数据结构:WORD FOREGROUND_RED 红色 FOREGROUND_GREEN 绿色 FOREGROUND_BLUE 蓝色 FOREGROUND_INTENSITY 加重 BACKGROUND_ RED 红色 BACKGROUND_GREEN 绿色 BACKGROUND_ BLUE 蓝色 BACKGROUND_INTENSITY 加重 1、黄色? FOREGROUND_RED | FOREGROUND_GREEN 2、青色? FOREGROUND_BLUE | FOREGROUND_GREEN 3、紫色? FOREGROUND_BLUE | FOREGROUND_RED 4、白色? FOREGROUND_RED|FOREGROUND_BLUE |FOREGROUND_GREEN */ enum OUTPUT_TYPE { OT_NORMOL, OT_WARNING, OT_ERROR }; void setConsoleOutputColor(const OUTPUT_TYPE & type) { HANDLE hCon = ::GetStdHandle(STD_OUTPUT_HANDLE); unsigned short ForeColor = FOREGROUND_GREEN; unsigned short BackGroundColor = 0; switch (type) { case OT_NORMOL: ForeColor = FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN; break; case OT_WARNING: ForeColor = FOREGROUND_GREEN; break; case OT_ERROR: ForeColor = FOREGROUND_RED; break; } ::SetConsoleTextAttribute(hCon, ForeColor|BackGroundColor); } int _tmain(int argc, _TCHAR* argv[]) { setConsoleOutputColor(OT_NORMOL); printf("Info: The script was loaded successfully! /n"); printf("Info: The script was loaded successfully! /n"); printf("Info: The script was loaded successfully! /n"); printf("Info: The script was loaded successfully! /n"); setConsoleOutputColor(OT_WARNING); printf("Warning: There is something wrong! /n"); printf("Warning: There is something wrong! /n"); printf("Warning: There is something wrong! /n"); printf("Warning: There is something wrong! /n"); setConsoleOutputColor(OT_ERROR); printf("Error: The script could not be loaded successfully! /n"); printf("Error: The script could not be loaded successfully! /n"); printf("Error: The script could not be loaded successfully! /n"); printf("Error: The script could not be loaded successfully! /n"); setConsoleOutputColor(OT_NORMOL); printf("Info: All is well! /n"); printf("Info: All is well! /n"); printf("Info: All is well! /n"); printf("Info: All is well! /n"); system("pause"); return 0; }