![](/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.