问题描述
如何在Windows的控制台应用程式中变更字型大小?最简单的方法?
使用 system()
和windows.h改变控制台颜色有什么区别?
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?
推荐答案
您可以使用 SetCurrentConsoleFontEx
更改字体大小。
以下是一个小例子,您 #include< cwchar>
和 #include< windows.h>
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";
如果您选择 Arial 或其他,您可能必须字体大小宽度。有关的更多信息。
If you choose Arial or others, you may have to give it a font size width. For more information.
system()
调用和使用 Windows.h
是 system()
调用是资源重和不安全。更多信息
The difference between system()
calls and using Windows.h
is that system()
calls are resource heavy and unsafe. More information here.
这篇关于如何更改控制台字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!