C++ 如何更改控制台字体大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35382432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the console font size
提问by Mekacher Anis
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?
如何在 Windows 上的控制台应用程序中更改字体大小?最简单的方法?使用system("")
和 windows.h更改控制台颜色有什么区别?
回答by Andreas DM
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>
您可以使用 更改字体大小SetCurrentConsoleFontEx
。
下面是一个你可以玩的小例子,确保你#include <cwchar>
和#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 Arialor others, you may have to give it a font size width. For more information.
如果您选择Arial或其他字体,您可能需要为其指定字体大小宽度。欲了解更多信息。
The difference between system()
calls and using Windows.h
is that system()
calls are resource heavy and unsafe. More information here.
之间的区别system()
调用和使用Windows.h
的是system()
电话是沉重的资源和不安全。更多信息在这里。