- set a Unicode capable font for the Windows console.

The default raster font only contains the OEM 437 code page which is quite useless.
This commit is contained in:
Christoph Oelckers 2019-03-16 10:50:53 +01:00
parent dbd6c2eabf
commit 714c656753
1 changed files with 24 additions and 6 deletions

View File

@ -878,12 +878,7 @@ void DoMain (HINSTANCE hInstance)
}
if (StdOut == NULL)
{
// AttachConsole was introduced with Windows XP. (OTOH, since we
// have to share the console with the shell, I'm not sure if it's
// a good idea to actually attach to it.)
typedef BOOL (WINAPI *ac)(DWORD);
ac attach_console = kernel != NULL ? (ac)GetProcAddress(kernel, "AttachConsole") : NULL;
if (attach_console != NULL && attach_console(ATTACH_PARENT_PROCESS))
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD foo; WriteFile(StdOut, "\n", 1, &foo, NULL);
@ -893,6 +888,29 @@ void DoMain (HINSTANCE hInstance)
{
StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
}
// These two functions do not exist in Windows XP.
BOOL (WINAPI* p_GetCurrentConsoleFontEx)(HANDLE hConsoleOutput, BOOL bMaximumWindow, PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx);
BOOL (WINAPI* p_SetCurrentConsoleFontEx)(HANDLE hConsoleOutput, BOOL bMaximumWindow, PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx);
p_SetCurrentConsoleFontEx = (decltype(p_SetCurrentConsoleFontEx))GetProcAddress(kernel, "SetCurrentConsoleFontEx");
p_GetCurrentConsoleFontEx = (decltype(p_GetCurrentConsoleFontEx))GetProcAddress(kernel, "GetCurrentConsoleFontEx");
if (p_SetCurrentConsoleFontEx && p_GetCurrentConsoleFontEx)
{
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
if (p_GetCurrentConsoleFontEx(StdOut, false, &cfi))
{
if (*cfi.FaceName == 0) // If the face name is empty, the default (useless) raster font is actoive.
{
//cfi.dwFontSize = { 8, 14 };
wcscpy(cfi.FaceName, L"Lucida Console");
cfi.FontFamily = FF_DONTCARE;
p_SetCurrentConsoleFontEx(StdOut, false, &cfi);
}
}
}
FancyStdOut = true;
}
}