#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
// Defaults
wchar_t fontNameW[LF_FACESIZE] = L"Courier New";
int fontSizeY = 20;
// Parse font name from argv[1]
if (argc >= 2) {
MultiByteToWideChar(CP_ACP, 0, argv[1], -1, fontNameW, LF_FACESIZE);
}
// Parse font size from argv[2]
if (argc >= 3) {
fontSizeY = atoi(argv[2]);
if (fontSizeY <= 0 || fontSizeY > 100) {
fprintf(stderr, "Invalid font size: %s\n", argv[2]);
return 1;
}
}
printf("Args: argc=%d\n", argc);
for (int i = 0; i < argc; i++) {
printf("argv[%d] = '%s'\n", i, argv[i]);
}
// Get console handle
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsole == INVALID_HANDLE_VALUE) {
fprintf(stderr, "Error: GetStdHandle failed.\n");
return 2;
}
// Fill in CONSOLE_FONT_INFOEX
CONSOLE_FONT_INFOEX cfi;
memset(&cfi, 0, sizeof(cfi));
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = fontSizeY;
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
wcscpy_s(cfi.FaceName, LF_FACESIZE, fontNameW);
DWORD mode;
if (!GetConsoleMode(hConsole, &mode)) {
fprintf(stderr, "Console handle is not interactive (detached or redirected).\n");
return 6;
}
// Apply font
if (!SetCurrentConsoleFontEx(hConsole, FALSE, &cfi)) {
fprintf(stderr, "Error: SetCurrentConsoleFontEx failed.\n");
return 3;
}
wprintf(L"Font set to \"%s\" size %d.\n", fontNameW, fontSizeY);
return 0;
}