0

I highly doubt this is possible, but I'm currently making some sort of game using C and Codeblocks, and that would be really helpful. Basically, what I need is a program that changes the text font the CMD uses. By default it's Consolas at size 16 I think, but I need it to be that square 8x8 font in CMD. Does anyone know if there's any way to do that?

Edit:

I should clarify, other people will be running this code on different computers, and they likely won't know it's meant to be like that. I could put a warning at the begining, but a way to directly do it with some code would be the best.

Abra
  • 19,142
  • 7
  • 29
  • 41
  • 2
    It's a bit tricky: check the answer to [this question](https://stackoverflow.com/questions/33975912/how-to-set-console-font-to-raster-font-programmatically). – Alex Sveshnikov Mar 02 '20 at 13:31
  • have you checked this https://stackoverflow.com/questions/25380476/how-to-change-cmd-font-size-without-going-through-properties – Landstalker Mar 02 '20 at 14:00
  • 1
    A Windows console application coded in C can make use of the Windows [Console API](https://learn.microsoft.com/en-us/windows/console/using-the-console) containing the function [SetCurrentConsoleFontEx](https://learn.microsoft.com/en-us/windows/console/setcurrentconsolefontex) and lots of other functions giving the program written in C full control over all properties of a console window opened on starting the console application or opened before starting the console application. – Mofi Mar 02 '20 at 15:09
  • The console application written in C should restore initial console properties (font, font size, window height and width, foreground and background color, etc.) before exiting in case of being started from within a command prompt window. It is not funny for a user if starting from within a command prompt window a console application results in a permanent change of the console window even after the executable terminated itself and the user has to close the command prompt window and open a new one to have the console window again with the preferred properties. – Mofi Mar 02 '20 at 15:12
  • The main advantage of using the console API functions is that the console application works on any Windows from Windows XP to currently latest Windows 10 independent on what is the default font, font size, window width, window height, as defined by the version of Windows respectively what the user configured as preferred properties for a console window. For example the OEM font Terminal is the default on Windows 7 and not Consolas as on Windows 8 and later Windows versions. An application written in C using `GetCurrentConsoleFontEx` and `SetCurrentConsoleFontEx` is independent on defaults. – Mofi Mar 02 '20 at 15:22

3 Answers3

1

Not the exact answer that you will be looking for...

You can manually select window settings enter image description here

And this will be applied always when using that console/instance on that computer.

The only adjustment as far as i am aware of is that you can only change the colors. but not font size programatically..

CoffeDev
  • 258
  • 2
  • 12
0

So the first thing that came into my mind is RMB on CMD -> Settings, then go to Font, and select which you want. Or should it be done by code?

lumenn
  • 11
  • 1
0

You can look at Console Virtual Terminal Sequences (CVTS) for various text font and color, etc. that can be changed on a Windows CMD window.
The following example is provided in a page that describes CVTS.

I ran the following in a Code::Blocks, console app to test: (This and other examples are included at the bottom of the link above.)

Note: ENABLE_VIRTUAL_TERMINAL_PROCESSING is needed. If you environment does not already include it, include it as I have shown below, otherwise leave it out.(my Windows 10 environment did not have it)

#include <stdio.h>
#include <wchar.h>
#include <windows.h>

#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif

int main()
{
    // Set output mode to handle virtual terminal sequences
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    if (hOut == INVALID_HANDLE_VALUE)
    {
        return GetLastError();
    }

    DWORD dwMode = 0;
    if (!GetConsoleMode(hOut, &dwMode))
    {
        return GetLastError();
    }

    dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
    if (!SetConsoleMode(hOut, dwMode))
    {
        return GetLastError();
    }

    // Try some Set Graphics Rendition (SGR) terminal escape sequences
    wprintf(L"\x1b[31mThis text has a red foreground using SGR.31.\r\n");
    wprintf(L"\x1b[1mThis text has a bright (bold) red foreground using SGR.1 to affect the previous color setting.\r\n");
    wprintf(L"\x1b[mThis text has returned to default colors using SGR.0 implicitly.\r\n");
    wprintf(L"\x1b[34;46mThis text shows the foreground and background change at the same time.\r\n");
    wprintf(L"\x1b[0mThis text has returned to default colors using SGR.0 explicitly.\r\n");
    wprintf(L"\x1b[31;32;33;34;35;36;101;102;103;104;105;106;107mThis text attempts to apply many colors in the same command. Note the colors are applied from left to right so only the right-most option of foreground cyan (SGR.36) and background bright white (SGR.107) is effective.\r\n");
    wprintf(L"\x1b[39mThis text has restored the foreground color only.\r\n");
    wprintf(L"\x1b[49mThis text has restored the background color only.\r\n");

    return 0;
}
ryyker
  • 22,849
  • 3
  • 43
  • 87