Skip to content

Commit

Permalink
jamulussoftware#2688 Make Windows console handling slick
Browse files Browse the repository at this point in the history
  • Loading branch information
pljones committed Aug 31, 2024
1 parent 5227d1c commit 9342831
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions Jamulus.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 9342831

Please sign in to comment.