C++ Console App Font Change

Hi,

How can I make the Font Larger in a console application?

I am using Code::Blocks C++.

Thank You!
Last edited on
If you use Windows you can use SetCurrentConsoleFontEx
https://docs.microsoft.com/en-us/windows/console/setcurrentconsolefontex
// I found something that works with Code::Blocks 17.12 , C++, Console App.
/*
The problem now is that when i increase the size of the font,
the console window gets larger as if the resolution is decreasing
*/
#define _WIN32_WINNT 0x0601
#include<windows.h>
#include<iostream>

using namespace std;


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;

//the function declaration begins

#ifdef __cplusplus

extern "C" {
#endif

BOOL WINAPI SetCurrentConsoleFontEx(HANDLE hConsoleOutput, BOOL bMaximumWindow,
PCONSOLE_FONT_INFOEX
lpConsoleCurrentFontEx);

#ifdef __cplusplus
}


#endif
//the function declaration ends


string uname;
int main()
{
int
newWidth=14, // experiment here for changing of font size
newHeight=28; // beware that the console window screen resolution changes also

CONSOLE_FONT_INFOEX fontStructure={0};
fontStructure.cbSize=sizeof(fontStructure);
fontStructure.dwFontSize.X=newWidth;
fontStructure.dwFontSize.Y=newHeight;
HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
SetCurrentConsoleFontEx(hConsole, true, &fontStructure);
cout <<"\nHello What is your name?"<<endl;
cin >>uname;
cout << "Hello "<<uname<<endl;
system("pause");
}


Topic archived. No new replies allowed.