WIN32: Add option to disable the console window, keeping the current default of enabling the console window.

This commit is contained in:
Travis Howell 2011-06-30 11:17:58 +10:00
parent eec84253f0
commit eae06884b6
5 changed files with 31 additions and 52 deletions

2
README
View file

@ -943,6 +943,7 @@ arguments -- see the next section.
-z, --list-games Display list of supported games and exit
-t, --list-targets Display list of configured targets and exit
--list-saves=TARGET Display a list of savegames for the game (TARGET) specified
--console Enable the console window (default: enabled) (Windows only)
-c, --config=CONFIG Use alternate configuration file
-p, --path=PATH Path to where the game is installed
@ -1975,6 +1976,7 @@ The following keywords are recognized:
confirm_exit bool Ask for confirmation by the user before quitting
(SDL backend only).
console bool Enable the console window (default: enabled) (Windows only).
cdrom number Number of CD-ROM unit to use for audio. If
negative, don't even try to access the CD-ROM.
joystick_num number Number of joystick device to use for input

View file

@ -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)

View file

@ -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);

View file

@ -65,6 +65,9 @@ static const char HELP_STRING[] =
" -z, --list-games Display list of supported games and exit\n"
" -t, --list-targets Display list of configured targets and exit\n"
" --list-saves=TARGET Display a list of savegames for the game (TARGET) specified\n"
#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
" --console Enable the console window (default:enabled)\n"
#endif
"\n"
" -c, --config=CONFIG Use alternate configuration file\n"
" -p, --path=PATH Path to where the game is installed\n"
@ -231,13 +234,6 @@ void registerDefaults() {
ConfMan.registerDefault("record_temp_file_name", "record.tmp");
ConfMan.registerDefault("record_time_file_name", "record.time");
#if 0
// NEW CODE TO HIDE CONSOLE FOR WIN32
#ifdef WIN32
// console hiding for win32
ConfMan.registerDefault("show_console", false);
#endif
#endif
}
//
@ -554,14 +550,11 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
END_OPTION
#endif
#if 0
// NEW CODE TO HIDE CONSOLE FOR WIN32
#ifdef WIN32
// console hiding for win32
DO_LONG_OPTION_BOOL("show-console")
#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
// Optional console window on Windows (default: enabled)
DO_LONG_OPTION_BOOL("console")
END_OPTION
#endif
#endif
unknownOption:
// If we get till here, the option is unhandled and hence unknown.

View file

@ -44,6 +44,7 @@ Name: es; MessagesFile: compiler:Languages\Spanish.isl
[Icons]
Name: {group}\{cm:UninstallProgram, ScummVM}; Filename: {uninstallexe}
Name: {group}\ScummVM; Filename: {app}\scummvm.exe; WorkingDir: {app}; Comment: scummvm; Flags: createonlyiffileexists; IconIndex: 0
Name: {group}\ScummVM (noconsole); Filename: {app}\scummvm.exe; Parameters: "--no-console"; WorkingDir: {app}; Comment: scummvm; Flags: createonlyiffileexists; IconIndex: 0
Name: {group}\Authors; Filename: {app}\AUTHORS.txt; WorkingDir: {app}; Comment: AUTHORS; Flags: createonlyiffileexists
Name: {group}\Copying; Filename: {app}\COPYING.txt; WorkingDir: {app}; Comment: COPYING; Flags: createonlyiffileexists
Name: {group}\Copying.LGPL; Filename: {app}\COPYING.LGPL.txt; WorkingDir: {app}; Comment: COPYING.LGPL; Flags: createonlyiffileexists