c/c++程序设计实验系统中怎么样设置文本颜色
3个回答
展开全部
如果是控制台的程序,可以这样做:
#include<Windows.h>
void main()
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout,
FOREGROUND_GREEN|FOREGROUND_INTENSITY);
printf("绿色\n");
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED|FOREGROUND_INTENSITY);
printf("红色\n");
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED|FOREGROUND_BLUE);
printf("粉红\n");
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
printf("加强以后的粉红\n");
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
printf("颜色可以自己混合哦\n");
system("pause");
}
如果不是控制台的,MFC的话,就看看GDI吧
#include<Windows.h>
void main()
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout,
FOREGROUND_GREEN|FOREGROUND_INTENSITY);
printf("绿色\n");
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED|FOREGROUND_INTENSITY);
printf("红色\n");
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED|FOREGROUND_BLUE);
printf("粉红\n");
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
printf("加强以后的粉红\n");
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
printf("颜色可以自己混合哦\n");
system("pause");
}
如果不是控制台的,MFC的话,就看看GDI吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询