程序代码:
#include <stdio.h>
#include <windows.h>
typedef struct _CONSOLE_FONT_
{
DWORD index;
COORD dim;
} CONSOLE_FONT, *PCONSOLE_FONT;
typedef BOOL WINAPI (*SETCONSOLEFONT)(HANDLE, DWORD);
typedef BOOL WINAPI (*GETCONSOLEFONTINFO)(HANDLE, BOOL, DWORD, PCONSOLE_FONT);
typedef DWORD WINAPI (*GETNUMBEROFCONSOLEFONTS)();
int main(void)
{
HMODULE hKernel32 = LoadLibrary("kernel32.dll");
if (hKernel32 == 0) return 0;
SETCONSOLEFONT SetConsoleFont = (SETCONSOLEFONT)GetProcAddress(hKernel32, "SetConsoleFont");
GETCONSOLEFONTINFO GetConsoleFontInfo = (GETCONSOLEFONTINFO)GetProcAddress(hKernel32, "GetConsoleFontInfo");
GETNUMBEROFCONSOLEFONTS GetNumberOfConsoleFonts = (GETNUMBEROFCONSOLEFONTS)GetProcAddress(hKernel32, "GetNumberOfConsoleFonts");
HANDLE hSTD = GetStdHandle(STD_OUTPUT_HANDLE);
//SetConsoleFont(hSTD, 2);
//SetConsoleFont(hSTD, 15);
SetConsoleFont(hSTD, 17);
DWORD dwFonts = GetNumberOfConsoleFonts();
if (dwFonts > 50) dwFonts = 50;
CONSOLE_FONT stFonts[50] = {0};
GetConsoleFontInfo(hSTD, FALSE, dwFonts, stFonts);
DWORD i;
for (i=0; i<dwFonts; i++)
{
stFonts[i].dim = GetConsoleFontSize(hSTD, stFonts[i].index);
printf("%d, %hd, %hd\n", stFonts[i].index, stFonts[i].dim.X, stFonts[i].dim.Y);
}
FreeLibrary(hKernel32);
return 0;
}