#include <stdio.h>
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE g_hStdout = GetStdHandle( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
if ( g_hStdout == NULL || ! GetConsoleScreenBufferInfo( g_hStdout, &csbiInfo))
{
printf( "GetConsoleScreenBufferInfo Console Error" );
return 0;
}
wOldColorAttrs = csbiInfo.wAttributes;
// Blue --> foreground
::SetConsoleTextAttribute( g_hStdout, FOREGROUND_BLUE | FOREGROUND_INTENSITY );
printf( "This is blue text\n" );
::SetConsoleTextAttribute( g_hStdout, wOldColorAttrs);
::SetConsoleTextAttribute( g_hStdout, FOREGROUND_GREEN | FOREGROUND_INTENSITY );
printf( "This is green text\n" );
::SetConsoleTextAttribute( g_hStdout, wOldColorAttrs);
::SetConsoleTextAttribute( g_hStdout, FOREGROUND_RED | FOREGROUND_INTENSITY );
printf( "This is red text\n" );
::SetConsoleTextAttribute( g_hStdout, wOldColorAttrs);
::SetConsoleTextAttribute( g_hStdout, BACKGROUND_BLUE | FOREGROUND_INTENSITY );
printf( "This is white text with blue background \n" );
::SetConsoleTextAttribute( g_hStdout, wOldColorAttrs);
return 0;
}
在控制台程序中输出彩色的字符串
在控制台程序中输出彩色字符
最新推荐文章于 2024-04-11 17:11:31 发布