From 93428317f64ca43aa1907ae6fe7fe6a5ca1d0dda Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sat, 2 Jul 2022 17:23:16 +0100 Subject: [PATCH] #2688 Make Windows console handling slick --- Jamulus.pro | 1 + src/main.cpp | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Jamulus.pro b/Jamulus.pro index e46ad40929..b28741b646 100644 --- a/Jamulus.pro +++ b/Jamulus.pro @@ -88,6 +88,7 @@ DEFINES += APP_VERSION=\\\"$$VERSION\\\" \ DEFINES += QT_NO_DEPRECATED_WARNINGS win32 { + CONFIG += console # fixes issue with app going into background DEFINES -= UNICODE # fixes issue with ASIO SDK (asiolist.cpp is not unicode compatible) DEFINES += NOMINMAX # solves a compiler error in qdatetime.h (Qt5) RC_FILE = src/res/win-mainicon.rc diff --git a/src/main.cpp b/src/main.cpp index 42d17a8dea..dbccfd36e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -131,14 +131,6 @@ int main ( int argc, char** argv ) Q_UNUSED ( bCustomPortNumberGiven ) #endif -#if !defined( HEADLESS ) && defined( _WIN32 ) - if ( AttachConsole ( ATTACH_PARENT_PROCESS ) ) - { - freopen ( "CONOUT$", "w", stdout ); - freopen ( "CONOUT$", "w", stderr ); - } -#endif - // When adding new options, follow the same order as --help output // QT docu: argv()[0] is the program name, argv()[1] is the first @@ -808,6 +800,14 @@ int main ( int argc, char** argv ) #endif } +#if defined( _WIN32 ) + // If we are using the GUI, minimize any attached console + if ( bUseGUI && ::GetConsoleWindow() ) + { + ::ShowWindow ( ::GetConsoleWindow(), SW_SHOWMINNOACTIVE ); + } +#endif + // Application/GUI setup --------------------------------------------------- // Application object #ifdef HEADLESS @@ -1069,6 +1069,13 @@ int main ( int argc, char** argv ) activity.EndActivity(); #endif +#if defined( _WIN32 ) + // If we are using the GUI, restore any attached console + if ( bUseGUI && ::GetConsoleWindow() ) + { + ::ShowWindow ( ::GetConsoleWindow(), SW_SHOWNORMAL ); + } +#endif return 0; }