Help with SetCurrentConsoleFontEx function

So, I'm making a program in C++ that emulates a full screen console...
I used SetCurrentConsoleFontEx to set the font to 12x16 but it sucks...
Anyway, I read here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682069(v=vs.85).aspx
that also the console font can be changed, but I can't make it work! How can i set the font to Lucida Console?
This is the function I use to change font size:
1
2
3
4
5
6
7
8
9
void setFontSize(int x, int y)
{
	PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx = new CONSOLE_FONT_INFOEX();
	lpConsoleCurrentFontEx->cbSize = sizeof(CONSOLE_FONT_INFOEX);
	GetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), NULL, lpConsoleCurrentFontEx);
	lpConsoleCurrentFontEx->dwFontSize.X = x;
	lpConsoleCurrentFontEx->dwFontSize.Y = y;
	SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), NULL, lpConsoleCurrentFontEx);
}
You can only use (x, y) values that exist. To see what's available look at the fonts listed in the Properties dialog of a console window.

Only a single value is given for Lucide Console, which is the font height (Y), so this should work (for values which exist, which means ... 12 14 16 18 20 24 ...)

1
2
3
4
5
6
7
8
9
void setFontSize(int FontSize)
{
    CONSOLE_FONT_INFOEX info = {0};
    info.cbSize       = sizeof(info);
    info.dwFontSize.Y = FontSize; // leave X as zero
    info.FontWeight   = FW_NORMAL;
    wcscpy(info.FaceName, L"Lucida Console");
    SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), NULL, &info);
}


Andy

PS you code is leaking the CONSOLE_FONT_INFOEX you allocated using new. You could free id with delete, but it's easier to just use a stack variable instead.
Last edited on
Wow it works! Thank you really much! :D
Topic archived. No new replies allowed.