# HG changeset patch # User Darkvater # Date 1157665941 0 # Node ID 2dcc4802b1e9c830721649293aa41d48f66a2ef2 # Parent c4ed5229b09c7845296b17f1703f8415fc9ea217 (svn r6420) -Feature [Win32]: Use an existing console if openttd was started from one. Unfortunately this only works for WindowsXP or higher, all older MS-OS's are stuck with the old behaviour. diff --git a/win32.c b/win32.c --- a/win32.c +++ b/win32.c @@ -786,16 +786,27 @@ return n; } +#ifndef ATTACH_PARENT_PROCESS +#define ATTACH_PARENT_PROCESS ((DWORD)-1) +#endif + void CreateConsole(void) { HANDLE hand; CONSOLE_SCREEN_BUFFER_INFO coninfo; + BOOL (WINAPI *AttachConsole)(DWORD); if (_has_console) return; _has_console = true; - AllocConsole(); + /* Attach to an existing console if one exists. Unfortunately this function + * only exists on WindowsXP or higher, so for all other users out there: + * you're stuck with an additional console even if you started openttd from + * the command line */ + if (!LoadLibraryList((Function*)&AttachConsole, "kernel32.dll\0AttachConsole\0") || + !AttachConsole(ATTACH_PARENT_PROCESS)) + AllocConsole(); hand = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hand, &coninfo);