C 修改命令行文本颜色

#include <Windows.h>
#include <stdio.h>

int main()
{
    HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
    WORD wOldColorAttrs;
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

    /*
    * First save the current color information
    */
    GetConsoleScreenBufferInfo(h, &csbiInfo);
    wOldColorAttrs = csbiInfo.wAttributes;

    /*
    * Set the new color information
    */
    SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_INTENSITY);

    printf("This is a test\n");
    /*
    * Restore the original colors
    */
    SetConsoleTextAttribute(h, wOldColorAttrs);
}

 

posted @ 2014-07-30 10:07  莫压枯枯地  阅读(406)  评论(0编辑  收藏  举报