程序题目:Press any key to change color, do you want to try it. Please hurry up!

#include "conio.h"
#include <stdio.h>
#include "windows.h"

int textbackground(short iColor)
{
    HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbInfo;
    GetConsoleScreenBufferInfo(hd, &csbInfo);
    return SetConsoleTextAttribute(hd, (iColor<<4)|(csbInfo.wAttributes&~0xF0));
}
void main(void)
{
    int color;
    for(color=0;color<8;color++)
    {
        textbackground(color);//设置文本的背景颜色
        cprintf("this is color%d\r\n",color);
        cprintf("press any key to continue\r\n");
        getch();//输入的字符看不见
    }
}

关于在VS2010下变换字体的颜色

载自https://blog.csdn.net/canlan818/article/details/8862795

猜你喜欢

转载自blog.csdn.net/u012133341/article/details/81487802