#include <windows.h>
#include <string.h>
bool setConsoleFontSize(HANDLE console, COORD dwFontSize){
CONSOLE_FONT_INFOEX info{ sizeof(CONSOLE_FONT_INFOEX) };
if (!GetCurrentConsoleFontEx(console, false, &info))
return false;
info.dwFontSize = dwFontSize;
return SetCurrentConsoleFontEx(console, false, &info);
}
void getConsoleSize(HANDLE console, short & width, short & height){
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
GetConsoleScreenBufferInfo(console, &bufferInfo);
width = bufferInfo.srWindow.Right;
height = bufferInfo.srWindow.Bottom;
}
void niceText(const char * text, unsigned short baseColor = 0x07, unsigned short specialColor = 0x07){
int length = strlen(text);
unsigned short * attributes = new unsigned short[length];
unsigned short * highLightAttributes = new unsigned short[length];
for (int i = 0; i < length; i++){
if (text[i] >= 0x20){
attributes[i] = baseColor;
highLightAttributes[i] = baseColor | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY;
}
else{
attributes[i] = specialColor;
highLightAttributes[i] = specialColor | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY;
}
}
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
setConsoleFontSize(console, {12, 16});
short width, height;
getConsoleSize(console, width, height);
COORD centeredPosition = {width/2 - length/2, height/2};
COORD position = { centeredPosition.X, centeredPosition.Y };
unsigned long charactersWritten = 0;
for (int i = 0; i < length; i++){
position.X = centeredPosition.X + i;
WriteConsoleOutputCharacterA(console, text + i, 1, position, &charactersWritten);
WriteConsoleOutputAttribute(console, attributes + i, 1, position, &charactersWritten);
Sleep(200);
}
Sleep(1000);
for (int i = 0; i < length; i++){
if (i > 0){
WriteConsoleOutputAttribute(console, attributes + i - 1, 1, position, &charactersWritten);
}
position.X = centeredPosition.X + i;
WriteConsoleOutputAttribute(console, highLightAttributes + i, 1, position, &charactersWritten);
Sleep(100);
}
WriteConsoleOutputAttribute(console, attributes + length - 1, 1, position, &charactersWritten);
Sleep(1000);
delete[] attributes;
delete[] highLightAttributes;
}
int main(int argc, char ** argv, char ** env){
niceText("I \03 C++", 0x07, 0x04);
return 0;
}
Comments
0 B
|👍
/👎
0 B
|👍
/👎