如何在Visual C++ 6.0中任意实现C++语言的输出字体颜色和背景的改变?

2025-04-05 11:23:06
推荐回答(1个)
回答1:

void printString(const wchar_t* cs) {
if (cs == NULL) {
return;
}
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), cs, wcslen(cs), 0, NULL);
}

void printErrorString(const wchar_t* cs) {
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_INTENSITY);
printString(cs);
SetConsoleTextAttribute(h,
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
}

参考上面的代码;
也就是使用win32 API, SetConsoleTextAttribute 和 WriteConsoleW