How to set a console font to a Bitmap font programmatically?

How can I make sure the current command line font is the default Raster font at runtime? I am using C ++ with WinApi.

I have currently used GetConsoleFontEx();and SetConsoleFontEx();, but I have not been able to find the correct value for the property CONSOLE_FONT_INFOEX FaceName. I found several examples on the Internet where the font was installed on Lucida and / or Consolas, but this is not what I am looking for.

Here is a snippet of my current code:

COORD fs = {8, 8};
CONSOLE_FONT_INFOEX cfie = {0};
cfie.cbSize = sizeof(cfie);

GetCurrentConsoleFontEx(hOut, 0, &cfie);

char fn[] = "Raster"; // Not really doing anything
strcpy_s((char*)cfie.FaceName, 32, fn); // Not sure if this is right
cfie.dwFontSize.X = fs.X;
cfie.dwFontSize.Y = fs.Y;

SetCurrentConsoleFontEx(hOut, 0, &cfie);

I checked the return value SetCurrentConsoleFontEx(), and it is non-zero, which indicates a successful call. However, the font does not change.

+4
source share
1 answer

MS SetCurrentConsoleFontEx(), , , . , cue Enter .

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

int main(int argc, char** args)
{ 
    CONSOLE_FONT_INFOEX cfi;
    cfi.cbSize = sizeof cfi;
    cfi.nFont = 0;
    cfi.dwFontSize.X = 0;
    cfi.dwFontSize.Y = 20;
    cfi.FontFamily = FF_DONTCARE;
    cfi.FontWeight = FW_NORMAL;
    printf("A quick brown fox jumps over the lazy dog\n");

    printf("Setting to Lucida Console: press <Enter> ");
    getchar();
    wcscpy(cfi.FaceName, L"Lucida Console");
    SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);

    printf("Setting to Consolas: press <Enter> ");
    getchar();
    wcscpy(cfi.FaceName, L"Consolas");
    SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);

    printf("Press <Enter> to exit");
    getchar();
    return 0;
}
+4

Source: https://habr.com/ru/post/1617850/


All Articles