windows.h function SetCurrentConsoleFontEx() is missing from windows.h?

I have been tasked to write a windows program using nothing but the console(no window) and the windows.h header file. I want to change the size of the console and the font at the beginning of the program and have found functions to do so using the MSDN documentation. However, one of the functions, SetCurrentConsoleFontEx(), is supposedly not part of the scope, even though the MSDN documentation said it was included in wincon.h (part of windows.h).

Is there any reason other windows.h functions would work but this one would be missing? Also, is there any other functions I could use that would fulfill the same purpose in case it isn't actually part of windows.h?

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#define _WIN32_WINNT 0x0601
#include <windows.h>

using namespace std;

void changeWindowSize();
void changeFontAttributes();

const int MY_WIDTH = 800;
const int MY_HEIGHT = 1000;

const int CHAR_WIDTH = 6;
const int CHAR_HEIGTH = 8;

int main()
{
    //Increases the size of console
    changeWindowSize();

    //Decreases the size of font
    changeFontAttributes();

    //Wait to terminate program
    cin.ignore();
    return 0;
}

//Increases the size of console
void changeWindowSize()
{
    //Will be used to store where the window is
    RECT winSize;

    //Gets all of the consoles current attributes
    HWND console = GetConsoleWindow();
    
    GetWindowRect(console, &winSize);

    MoveWindow(console, winSize.left, winSize.top, MY_WIDTH, MY_HEIGHT, true);
}

//Decreases the size of font
void changeFontAttributes()
{
    //Default values
    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;

    PCONSOLE_FONT_INFOEX consoleFont;

    HANDLE toScreen;

    toScreen = GetStdHandle(STD_OUTPUT_HANDLE);

    //Sets new font sizes
    consoleFont->dwFontSize.X = CHAR_WIDTH;
    consoleFont->dwFontSize.Y = CHAR_HEIGTH;

    SetCurrentConsoleFontEx(toScreen, true, consoleFont);
}


All other functions are recognized with current headers, but I get this error message for SetCurrentConsoleFontEx:

H:\changingConsole\main.cpp\ 60 error: 'SetCurrentConsoleFontEx' was not declared in this scope

This function is implemented inside the changeFontAttributes() function at the bottom.

I am aware that the user can change console properties during run-time but I need the program to do it by itself.

Any suggestions are welcome, as I am still very new!
Last edited on
This is because you are using MingW which does not use exact replicas of the WinSDK header files or libraries. "SetCurrentConsoleFontEx()" is not defined in the version of 'Wincon.h' included with the default installation of the main MingW project. I suggest grabbing the WinSDK and the MSVS 2010 compiler (which works wonderfully with Code::Blocks btw) and using the tools designed for your system. You could try to find one of the MingW branches but that is hit or miss in my experience.
Your code works with g++ 4.8.0. Anyway, your changeFontAttributes function would crash because you do not allocate memory for consoleFont

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// compiles on g++ 4.8.0
void changeFontAttributes()
{
// CONSOLE_FONT_INFOEX is already declared in wincon.h, so you ndon;t need to define it again
    CONSOLE_FONT_INFOEX consoleFont; //allocate on stack
// in your code PCONSOLE_FONT_INFOEX is just a pointer

    HANDLE toScreen;

    toScreen = GetStdHandle(STD_OUTPUT_HANDLE);

    //Sets new font sizes
    consoleFont.dwFontSize.X = CHAR_WIDTH;
    consoleFont.dwFontSize.Y = CHAR_HEIGTH;

    SetCurrentConsoleFontEx(toScreen, true, &consoleFont);
}
Last edited on
@ Null: It's not the compiler that the OP has to update, it's the 'wincon.h' header file. If they need proof they can open it in a text file editor and use 'ctrl+F'. I'm running g++ 4.8.1 but the header file that comes with it does not define "SetCurrentConsoleFontEx()". In fact I just downloaded the 'w32api' package from MingW's site and this function still isn't included in there. So what are you including from? That's a serious question by the way, I just migrated to a new system and I can't remember what I had downloaded to fix issues like this.
I am using a lab computer and am not able to update any of this. Thank you so much for the answers though!
@Computergeek01: If I remember correctly, I used mingw-get which installed all packages http://sourceforge.net/projects/mingw/files/Installer/ <-- I think I got it from there but I'll check tomorrow
Topic archived. No new replies allowed.