From eae06884b6c6da23b7932ceba65e435d9be6ef82 Mon Sep 17 00:00:00 2001 From: Travis Howell Date: Thu, 30 Jun 2011 11:17:58 +1000 Subject: WIN32: Add option to disable the console window, keeping the current default of enabling the console window. --- backends/platform/sdl/win32/win32.cpp | 60 ++++++++++++----------------------- backends/platform/sdl/win32/win32.h | 1 + 2 files changed, 22 insertions(+), 39 deletions(-) (limited to 'backends') diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index 420ed2465b..c1b6c853e4 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -24,6 +24,7 @@ #define FORBIDDEN_SYMBOL_ALLOW_ALL #include "common/scummsys.h" +#include "common/config-manager.h" #include "common/error.h" #include "common/textconsole.h" @@ -44,46 +45,7 @@ #define DEFAULT_CONFIG_FILE "scummvm.ini" -//#define HIDE_CONSOLE - -#ifdef HIDE_CONSOLE -struct SdlConsoleHidingWin32 { - DWORD myPid; - DWORD myTid; - HWND consoleHandle; -}; - -// console hiding for win32 -static BOOL CALLBACK initBackendFindConsoleWin32Proc(HWND hWnd, LPARAM lParam) { - DWORD pid, tid; - SdlConsoleHidingWin32 *variables = (SdlConsoleHidingWin32 *)lParam; - tid = GetWindowThreadProcessId(hWnd, &pid); - if ((tid == variables->myTid) && (pid == variables->myPid)) { - variables->consoleHandle = hWnd; - return FALSE; - } - return TRUE; -} - -#endif - void OSystem_Win32::init() { -#ifdef HIDE_CONSOLE - // console hiding for win32 - SdlConsoleHidingWin32 consoleHidingWin32; - consoleHidingWin32.consoleHandle = 0; - consoleHidingWin32.myPid = GetCurrentProcessId(); - consoleHidingWin32.myTid = GetCurrentThreadId(); - EnumWindows (initBackendFindConsoleWin32Proc, (LPARAM)&consoleHidingWin32); - - if (!ConfMan.getBool("show_console")) { - if (consoleHidingWin32.consoleHandle) { - // We won't find a window with our TID/PID in case we were started from command-line - ShowWindow(consoleHidingWin32.consoleHandle, SW_HIDE); - } - } -#endif - // Initialize File System Factory _fsFactory = new WindowsFilesystemFactory(); @@ -96,6 +58,26 @@ void OSystem_Win32::init() { OSystem_SDL::init(); } +void OSystem_Win32::initBackend() { + // Console window is enabled by default on Windows + ConfMan.registerDefault("console", true); + + // Enable or disable the window console window + if (ConfMan.getBool("console")) { + if (AllocConsole()) { + freopen("CONIN$","r",stdin); + freopen("CONOUT$","w",stdout); + freopen("CONOUT$","w",stderr); + } + SetConsoleTitle("ScummVM Status Window"); + } else { + FreeConsole(); + } + + // Invoke parent implementation of this method + OSystem_SDL::initBackend(); +} + bool OSystem_Win32::hasFeature(Feature f) { if (f == kFeatureDisplayLogFile) diff --git a/backends/platform/sdl/win32/win32.h b/backends/platform/sdl/win32/win32.h index cc2fc51d36..b56997a63b 100644 --- a/backends/platform/sdl/win32/win32.h +++ b/backends/platform/sdl/win32/win32.h @@ -28,6 +28,7 @@ class OSystem_Win32 : public OSystem_SDL { public: virtual void init(); + virtual void initBackend(); virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); -- cgit v1.2.3