summaryrefslogtreecommitdiff
path: root/win32.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-09-07 21:52:21 +0000
committerDarkvater <Darkvater@openttd.org>2006-09-07 21:52:21 +0000
commitc1fa005024186113d43d7406b79e625c960b14c7 (patch)
treed3160fcbd7510e31f7f84ae26b74f891d9d5fef7 /win32.c
parent1735dfc81623d755bc7e5ea57c8c7ca8a794f628 (diff)
downloadopenttd-c1fa005024186113d43d7406b79e625c960b14c7.tar.xz
(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.
Diffstat (limited to 'win32.c')
-rw-r--r--win32.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/win32.c b/win32.c
index 4070f8546..9119aed37 100644
--- a/win32.c
+++ b/win32.c
@@ -786,16 +786,27 @@ static int ParseCommandLine(char *line, char **argv, int max_argc)
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);