4

I call GetCurrentConsoleFontEx and then call SetCurrentConsoleFontEx with the same information. I would have expected that setting the new_font = old_font would have no effect.

Clearly, I was naive.

The exact program is:

#define _WIN32_WINNT 0x0502
#include <Windows.h>
int main()
{
    HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_FONT_INFOEX cfi1, cfi2;
    cfi1.cbSize = sizeof(cfi1);
    cfi2.cbSize = sizeof(cfi2);
    if (0 == GetCurrentConsoleFontEx(out, false, &cfi1))
        return -1;
    if (0 == SetCurrentConsoleFontEx(out, false, &cfi1))
        return -1;
    if (0 == GetCurrentConsoleFontEx(out, false, &cfi2))
        return -1;
    return 0;
}

The program exits with code 0, so the API calls didn't fail.

From cfi1 to cfi2, the value of nFont, an index into a table of fonts, changed from 1 to 3. The size of the font's width and height, dwFontSize, changed from {12, 25} to {15, 31}.

Why is this happening?

EDIT: Calling GetConsoleFontSize when the second parameter for the calls is false returns the same font size as GetCurrentConsoleFontEx. When the second parameter is true, GetConsoleFontSize returns {12, 15} before and {23, 49} after. GetCurrentConsoleFontEx reports the font size to be {80, 20} both times. nFont still changes.

Weak to Enuma Elish
  • 4,622
  • 3
  • 24
  • 36
  • You should probably be checking for failure just to make sure nothing weird's going on. – Jonathan Potter Jan 31 '16 at 10:42
  • @JonathanPotter Oh yeah, I should add that. The original problem ran with the checks in place, and I removed them when shortening it down. – Weak to Enuma Elish Jan 31 '16 at 10:45
  • You should read the docs for GetCurrentConsoleFontEx more carefully. It implies that the font for `true` and `false` for the second parameter may be different. Furthermore, the description of `CONSOLE_FONT_INFOEX` says that you must call another function, `GetConsoleFontSize`, to get the font size. – Puppy Jan 31 '16 at 10:56
  • @Puppy I wouldn't expect it to change if I use the same true/false parameter for both calls. Also, changing it to `true` instead makes the font catastrophically larger. I just verified by using `GetConsoleFontSize` before and after, and the size returned by that matches the one returned by `GetCurrentConsoleFontEx`. – Weak to Enuma Elish Jan 31 '16 at 11:01

0 Answers0