File tree Expand file tree Collapse file tree 2 files changed +10
-19
lines changed Expand file tree Collapse file tree 2 files changed +10
-19
lines changed Original file line number Diff line number Diff line change 11#include <Windows.h>
22
3- // https://stackoverflow.com/a/57241985
4- void CreateConsole ()
3+ void openConsole (bool isShowConsole )
54{
6- if (!AllocConsole ()) {
7- // Add some error handling here.
8- // You can call GetLastError() to get more info about the error.
9- return ;
10- }
11-
12- // std::cout, std::clog, std::cerr, std::cin
13- FILE* fDummy ;
14- freopen_s (&fDummy , " CONOUT$" , " w" , stdout);
15- freopen_s (&fDummy , " CONOUT$" , " w" , stderr);
16- freopen_s (&fDummy , " CONIN$" , " r" , stdin);
17- SetConsoleTitle (TEXT (" Hyperion" ));
18- SetConsoleOutputCP (CP_UTF8);
5+ if (AttachConsole (ATTACH_PARENT_PROCESS ) || (isShowConsole && AllocConsole ())) {
6+ FILE * fp ;
7+ freopen_s (& fp , "CONOUT$" , "w" , stdout );
8+ freopen_s (& fp , "CONOUT$" , "w" , stderr );
9+ SetConsoleTitle (TEXT ("Hyperion" ));
10+ SetConsoleOutputCP (CP_UTF8 );
11+ }
1912}
Original file line number Diff line number Diff line change @@ -156,10 +156,8 @@ int main(int argc, char** argv)
156156 parser.process (*qApp);
157157
158158#ifdef WIN32
159- if (parser.isSet (consoleOption))
160- {
161- CreateConsole ();
162- }
159+ bool isShowConsole = parser.isSet (consoleOption);
160+ openConsole (isShowConsole);
163161#endif
164162
165163 if (parser.isSet (versionOption))
You can’t perform that action at this time.
0 commit comments