diff options
Diffstat (limited to 'platform/windows/display_server_windows.cpp')
-rw-r--r-- | platform/windows/display_server_windows.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index da2fc1c2c1..e4a7814cc1 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -1135,10 +1135,17 @@ void DisplayServerWindows::window_set_ime_position(const Point2i &p_pos, WindowI void DisplayServerWindows::console_set_visible(bool p_enabled) { _THREAD_SAFE_METHOD_ - if (console_visible == p_enabled) + if (console_visible == p_enabled) { return; - ShowWindow(GetConsoleWindow(), p_enabled ? SW_SHOW : SW_HIDE); - console_visible = p_enabled; + } + if (p_enabled && GetConsoleWindow() == nullptr) { // Open new console if not attached. + own_console = true; + AllocConsole(); + } + if (own_console) { // Note: Do not hide parent console. + ShowWindow(GetConsoleWindow(), p_enabled ? SW_SHOW : SW_HIDE); + console_visible = p_enabled; + } } bool DisplayServerWindows::is_console_visible() const { @@ -3019,7 +3026,18 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win shift_mem = false; control_mem = false; meta_mem = false; - console_visible = IsWindowVisible(GetConsoleWindow()); + + if (AttachConsole(ATTACH_PARENT_PROCESS)) { + FILE *_file = nullptr; + freopen_s(&_file, "CONOUT$", "w", stdout); + freopen_s(&_file, "CONOUT$", "w", stderr); + freopen_s(&_file, "CONIN$", "r", stdin); + + printf("\n"); + console_visible = true; + } else { + console_visible = false; + } hInstance = ((OS_Windows *)OS::get_singleton())->get_hinstance(); pressrc = 0; |