Compare commits
2 Commits
master
...
fix/window
Author | SHA1 | Date |
---|---|---|
Martchus | ab50f4e243 | |
Martchus | 469e16e673 |
|
@ -37,9 +37,27 @@ bool confirmPrompt(const char *message, Response defaultResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PLATFORM_WINDOWS
|
#ifdef PLATFORM_WINDOWS
|
||||||
|
/*!
|
||||||
|
* \brief Closes stdout, stdin and stderr and stops the console.
|
||||||
|
* \remarks Interanlly used by startConsole() to close the console when the application exits.
|
||||||
|
*/
|
||||||
|
void stopConsole()
|
||||||
|
{
|
||||||
|
fclose(stdout);
|
||||||
|
fclose(stdin);
|
||||||
|
fclose(stderr);
|
||||||
|
if(auto *consoleWindow = GetConsoleWindow()) {
|
||||||
|
PostMessage(consoleWindow, WM_KEYUP, VK_RETURN, 0);
|
||||||
|
FreeConsole();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Starts the console and sets the console output code page to UTF-8 if this is configured.
|
* \brief Starts the console and sets the console output code page to UTF-8 if this is configured.
|
||||||
* \remarks This method is only available on Windows and used to start a console from a GUI application.
|
* \remarks
|
||||||
|
* - only available under Windows
|
||||||
|
* - used to start a console from a GUI application
|
||||||
|
* - closes the console automatically when the application exists
|
||||||
*/
|
*/
|
||||||
void startConsole()
|
void startConsole()
|
||||||
{
|
{
|
||||||
|
@ -72,6 +90,8 @@ void startConsole()
|
||||||
#endif
|
#endif
|
||||||
// sync
|
// sync
|
||||||
ios::sync_with_stdio(true);
|
ios::sync_with_stdio(true);
|
||||||
|
// ensure the console prompt is shown again when app terminates
|
||||||
|
atexit(stopConsole);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -26,15 +26,19 @@ bool CPP_UTILITIES_EXPORT confirmPrompt(const char *message, Response defaultRes
|
||||||
|
|
||||||
#ifdef PLATFORM_WINDOWS
|
#ifdef PLATFORM_WINDOWS
|
||||||
void CPP_UTILITIES_EXPORT startConsole();
|
void CPP_UTILITIES_EXPORT startConsole();
|
||||||
|
void CPP_UTILITIES_EXPORT stopConsole();
|
||||||
std::pair<std::vector<std::unique_ptr<char[]> >, std::vector<char *> > CPP_UTILITIES_EXPORT convertArgsToUtf8();
|
std::pair<std::vector<std::unique_ptr<char[]> >, std::vector<char *> > CPP_UTILITIES_EXPORT convertArgsToUtf8();
|
||||||
# define CMD_UTILS_START_CONSOLE \
|
# define CMD_UTILS_START_CONSOLE \
|
||||||
::ApplicationUtilities::startConsole();
|
::ApplicationUtilities::startConsole();
|
||||||
|
# define CMD_UTILS_STOP_CONSOLE \
|
||||||
|
::ApplicationUtilities::stopConsole();
|
||||||
# define CMD_UTILS_CONVERT_ARGS_TO_UTF8 \
|
# define CMD_UTILS_CONVERT_ARGS_TO_UTF8 \
|
||||||
auto utf8Args = ::ApplicationUtilities::convertArgsToUtf8(); \
|
auto utf8Args = ::ApplicationUtilities::convertArgsToUtf8(); \
|
||||||
argv = utf8Args.second.data(); \
|
argv = utf8Args.second.data(); \
|
||||||
argc = static_cast<int>(utf8Args.second.size());
|
argc = static_cast<int>(utf8Args.second.size());
|
||||||
#else
|
#else
|
||||||
# define CMD_UTILS_START_CONSOLE
|
# define CMD_UTILS_START_CONSOLE
|
||||||
|
# define CMD_UTILS_STOP_CONSOLE
|
||||||
# define CMD_UTILS_CONVERT_ARGS_TO_UTF8
|
# define CMD_UTILS_CONVERT_ARGS_TO_UTF8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue