如何用c改变控制台字体以及字体大小?

测试平台:VS2017

关键代码
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof cfi;
cfi.nFont = 0;
cfi.dwFontSize.X = 0; //字宽
cfi.dwFontSize.Y = 20;//字高
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;//粗细
wcscpy_s(cfi.FaceName, L"Raster"); //设置字体,此处设为点阵字体
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);

关于CONSOLE_FONT_INFOEX 结构体的定义
typedef struct _CONSOLE_FONT_INFOEX {
ULONG cbSize;
DWORD nFont;
COORD dwFontSize;
UINT FontFamily;
UINT FontWeight;
WCHAR FaceName[LF_FACESIZE];
} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;

微软给出的成员变量解释
Members
cbSize
The size of this structure, in bytes. This member must be set to sizeof(CONSOLE_FONT_INFOEX) before calling GetCurrentConsoleFontEx or it will fail.

nFont
The index of the font in the system’s console font table.

dwFontSize
A COORD structure that contains the width and height of each character in the font, in logical units. The X member contains the width, while the Y member contains the height.

FontFamily
The font pitch and family. For information about the possible values for this member, see the description of the tmPitchAndFamily member of the TEXTMETRIC structure.

FontWeight
The font weight. The weight can range from 100 to 1000, in multiples of 100. For example, the normal weight is 400, while 700 is bold.

FaceName
The name of the typeface (such as Courier or Arial).

测试代码

#include <windows.h>
#include <stdio.h>
  • 17
    点赞
  • 117
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值