"CONSOLE_FONT_INFOEX was not declared in this scope"

Hi guys. I'm trying to do something that should be, in theory, very simple: change the font of windows command prompt.

I've found a few examples of how to do this, but none of them compile for me (using gcc/g++/MinGW in command prompt; however one should refer to this). Am I missing something import wise? I'm really at a loss here and google is failing me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <windows.h>
#include <wincon.h>
#include <string>
#include <iostream>
#include <fstream>
//#define _WIN32_WINNT 0x0601 //<- this just gives me warnings and doesn't help anything
//compiling this with g++ -std=c++11
//am I missing something in imports?
using namespace std;


int main() {
    int FontSize = 18;
    CONSOLE_FONT_INFOEX info = {0}; //<- "CONSOLE_FONT_INFOEX was not declared in this scope"
    info.cbSize       = sizeof(info);
    info.dwFontSize.Y = FontSize; // leave X as zero
    info.FontWeight   = FW_NORMAL;
    wcscpy(info.FaceName, L"Courier");
    SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), NULL, &info);

	cout << "Hello Courier!";

    return 0;
}
Last edited on
Hi CajunCoder, I had had the same problem as you, but I've found a solution.
(I use Code::Blocks 16.01 (mingw), windows 8.1)
I am going to provide you 2 ways of solving it:

1. Just as you showed in the program, using code:
(Also, good call with the _WIN32_WINNT)
For some reason you have to define the structure inside your program and declare the SetConsoleFont as shown below (using all 7 lines).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#define _WIN32_WINNT 0x0601
#include<windows.h>
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
int main()
{
    int
    newWidth=8,
    newHeight=8;
    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);
    system("pause");
}

Try it and see if magic happens.

2. Manually change the font (which is maybe useless for what you intend to do, as I've also wanted to change the font in real time, and you might probably know this by now):

-Compile the program and open the executable.
-Right-Click the Title Bar.
-Click "Properties".
-When the properties windows pops, it might be in the options tab (if you've never switched to another tab here), so go to the font tab.
-Here you can change the font style and sizes (I use the Raster font, with the 8x8 size to be able to create various shapes and even retro video games physics).
Topic archived. No new replies allowed.