I want to change the font style of Cmd

I want to change Cmd font with C coding.

But I don't know how to change it.

I want to change the main font -> Terminal Font.

This is my code

CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof cfi;
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = 16;
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
wcscpy_s(cfi.FaceName,9, L"Terminal");
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);

      

My development environment is on Windows 10.

+3


source to share


1 answer


The problem with the function SetCurrentConsoleFontEx()

is that the font width is not optional. You must use a value that matches the Y size and is supported by the selected font.

For the Terminal

following should work:

cfi.dwFontSize.X = 12;
cfi.dwFontSize.Y = 16;

      



If you want to check the font size, you can list the fonts. For example, with this little code:

// callback to display some infos about one font 
int CALLBACK logfont(_In_ const LOGFONT    *lplf, 
    _In_ const TEXTMETRIC *lptm,
    _In_       DWORD      dwType,
    _In_       LPARAM     lpData
    )
{
    wcout << L"Font " << (wchar_t*)lplf->lfFaceName << L" " << lplf->lfHeight<<L" "<<lplf->lfWidth <<endl;
    return 1;
}

// this callback is then used in a statement like:  
EnumFonts(GetDC((HWND)GetStdHandle(STD_OUTPUT_HANDLE)),L"Terminal", logfont, NULL);

      

For more details on installed fonts, this MSDN article might interest you.

+1


source







All Articles