mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-16 17:21:10 +00:00
- fix isolated console mode (i.e. launching from explorer.exe)
This commit is contained in:
parent
9a9440a6f7
commit
86cd212d7f
3 changed files with 29 additions and 18 deletions
|
@ -1361,7 +1361,7 @@ endif()
|
||||||
if( MSVC )
|
if( MSVC )
|
||||||
option ( CONSOLE_MODE "Compile as a console application" OFF )
|
option ( CONSOLE_MODE "Compile as a console application" OFF )
|
||||||
if ( CONSOLE_MODE )
|
if ( CONSOLE_MODE )
|
||||||
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE /ENTRY:wWinMainCRTStartup" )
|
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE /ENTRY:wmainCRTStartup" )
|
||||||
else()
|
else()
|
||||||
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:wWinMainCRTStartup" )
|
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:wWinMainCRTStartup" )
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -45,6 +45,11 @@
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#include <VersionHelpers.h>
|
#include <VersionHelpers.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <io.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(disable:4244)
|
#pragma warning(disable:4244)
|
||||||
#endif
|
#endif
|
||||||
|
@ -149,11 +154,22 @@ void I_SetIWADInfo()
|
||||||
|
|
||||||
bool isConsoleApp()
|
bool isConsoleApp()
|
||||||
{
|
{
|
||||||
DWORD pids[2];
|
static bool alreadychecked = false;
|
||||||
DWORD num_pids = GetConsoleProcessList(pids, 2);
|
static bool returnvalue;
|
||||||
bool win32con_is_exclusive = (num_pids <= 1);
|
|
||||||
|
|
||||||
return GetConsoleWindow() != NULL && !win32con_is_exclusive;
|
if (!alreadychecked)
|
||||||
|
{
|
||||||
|
DWORD pids[2];
|
||||||
|
DWORD num_pids = GetConsoleProcessList(pids, 2);
|
||||||
|
bool win32con_is_exclusive = (num_pids <= 1);
|
||||||
|
|
||||||
|
returnvalue = ((GetConsoleWindow() != NULL && !win32con_is_exclusive) || (GetStdHandle(STD_OUTPUT_HANDLE) != NULL));
|
||||||
|
alreadychecked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("isConsoleApp is %i\n", returnvalue);
|
||||||
|
|
||||||
|
return returnvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -183,19 +199,7 @@ int DoMain (HINSTANCE hInstance)
|
||||||
if (isConsoleApp())
|
if (isConsoleApp())
|
||||||
{
|
{
|
||||||
StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
BY_HANDLE_FILE_INFORMATION info;
|
FancyStdOut = IsWindows10OrGreater(); // Windows 8.1 and lower do not understand ANSI formatting.
|
||||||
|
|
||||||
if (!GetFileInformationByHandle(StdOut, &info) && StdOut != nullptr)
|
|
||||||
{
|
|
||||||
SetConsoleCP(CP_UTF8);
|
|
||||||
SetConsoleOutputCP(CP_UTF8);
|
|
||||||
DWORD mode;
|
|
||||||
if (GetConsoleMode(StdOut, &mode))
|
|
||||||
{
|
|
||||||
if (SetConsoleMode(StdOut, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING))
|
|
||||||
FancyStdOut = IsWindows10OrGreater(); // Windows 8.1 and lower do not understand ANSI formatting.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (Args->CheckParm("-stdout") || Args->CheckParm("-norun"))
|
else if (Args->CheckParm("-stdout") || Args->CheckParm("-norun"))
|
||||||
{
|
{
|
||||||
|
@ -514,6 +518,11 @@ CUSTOM_CVAR(Bool, disablecrashlog, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
|
int wmain()
|
||||||
|
{
|
||||||
|
return wWinMain(GetModuleHandle(0), 0, GetCommandLineW(), SW_SHOW);
|
||||||
|
}
|
||||||
|
|
||||||
int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE nothing, LPWSTR cmdline, int nCmdShow)
|
int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE nothing, LPWSTR cmdline, int nCmdShow)
|
||||||
{
|
{
|
||||||
g_hInst = hInstance;
|
g_hInst = hInstance;
|
||||||
|
|
|
@ -102,6 +102,7 @@
|
||||||
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
||||||
|
|
||||||
void DestroyCustomCursor();
|
void DestroyCustomCursor();
|
||||||
|
bool isConsoleApp();
|
||||||
|
|
||||||
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
||||||
|
|
||||||
|
@ -306,6 +307,7 @@ static void PrintToStdOut(const char *cpt, HANDLE StdOut)
|
||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD bytes_written;
|
DWORD bytes_written;
|
||||||
WriteFile(StdOut, printData.GetChars(), (DWORD)printData.Len(), &bytes_written, NULL);
|
WriteFile(StdOut, printData.GetChars(), (DWORD)printData.Len(), &bytes_written, NULL);
|
||||||
if (terminal)
|
if (terminal)
|
||||||
|
|
Loading…
Reference in a new issue