How to change the console font size
47,908
You can change the font size using SetCurrentConsoleFontEx
.
Below is a small example that you can play around with, make sure you #include <cwchar>
and #include <windows.h>
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = 0; // Width of each character in the font
cfi.dwFontSize.Y = 24; // Height
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
std::wcscpy(cfi.FaceName, L"Consolas"); // Choose your font
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
std::cout << "Font: Consolas, Size: 24\n";
If you choose Arial or others, you may have to give it a font size width. For more information.
The difference between system()
calls and using Windows.h
is that system()
calls are resource heavy and unsafe. More information here.
Author by
Mekacher Anis
Updated on April 19, 2020Comments
-
Mekacher Anis about 4 years
How can I change the font size in a console app on Windows? Simplest way? What is the difference between changing console color using
system("")
and windows.h? -
IInspectable over 8 years"If you choose Arial or others" - which ones? "[...] you may have to give it a font size width." - under what conditions?
-
dxiv over 8 yearsMaybe worth noting that
SetCurrentConsoleFontEx
requires Vista or later ( _WIN32_WINNT >= 0x0500). Also, the documentation is not clear on how exactlycfi.nFont = 0;
works ("nFont = The index of the font in the system's console font table."). -
serup over 7 yearsany chance you know how to do this on Ubuntu?