![](/img/trans.png)
[英]How to change/get the font(-size) in the “Console Application” using Windows API or internal command without changing the registry directly?
[英]How to change font size in console application using C
如何使用c更改打印字体的字体大小?
printf ("%c", map[x][y]);
我想打印一个大于程序中所有其他文本的数组。 有没有办法让这个声明更大?
虽然teppic对使用system()
的回答是有效的,但是为了做到这一点,调用外部程序却相当严厉。 至于David RF的答案 ,它是针对特定类型的终端(可能是兼容VT100的终端类型)进行硬编码的,并且不支持用户的实际终端类型。
在C中,您应该直接使用terminfo功能:
#include <term.h>
/* One-time initialization near the beginning of your program */
setupterm(NULL, STDOUT_FILENO, NULL);
/* Enter bold mode */
putp(enter_bold_mode);
printf("I am bold\n");
/* Turn it off! */
putp(exit_attribute_mode);
但是,正如teppic所说,不支持更改字体大小。 这是在用户的控制之下。
如果它是Linux(可能还有其他形式的Unix)你可以搞乱system
来改变一些终端设置,使它脱颖而出 - 虽然不是字体大小。 这种东西真的只适合简单的程序,而且显然不便携:
#include <stdio.h>
#include <stdlib.h>
[...]
printf("Normal text\n");
system("setterm -bold on");
printf("Bold text\n");
system("setterm -bold off");
否则,您可以通过printf
直接发送各种终端序列,它们将控制大多数Unix终端应用程序,例如\\033[31m
将在xterm中将文本更改为红色。 但是这些序列可以变化。
如果您使用某些unix,则可以尝试激活和取消激活粗体文本:
printf("\033[1m%c\033[0m", map[x][y]);
此代码适用于Win32应用程序(无论使用哪个子系统:WINDOWS或CONSOLE):
inline void setFontSize(int a, int b)
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx = new CONSOLE_FONT_INFOEX();
lpConsoleCurrentFontEx->cbSize = sizeof(CONSOLE_FONT_INFOEX);
GetCurrentConsoleFontEx(hStdOut, 0, lpConsoleCurrentFontEx);
lpConsoleCurrentFontEx->dwFontSize.X = a;
lpConsoleCurrentFontEx->dwFontSize.Y = b;
SetCurrentConsoleFontEx(hStdOut, 0, lpConsoleCurrentFontEx);
}
然后只需致电(例如):
setFontSize(20,20);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.