FreeRDP
Loading...
Searching...
No Matches
sdl_win32_console.cpp
1
20#include "sdl_win32_console.hpp"
21
22#include <cstdio>
23
24#if defined(_WIN32)
25#include <winpr/windows.h>
26#endif
27
28#if defined(_WIN32) && defined(WITH_WIN_CONSOLE)
29#include <io.h>
30#endif
31
32namespace sdl
33{
34 namespace win32
35 {
36 bool has_inherited_console()
37 {
38#if defined(_WIN32) && defined(WITH_WIN_CONSOLE)
39 const int file = _fileno(stdin);
40 const int tty = _isatty(file);
41 DWORD processes[2] = { 0 };
42 const DWORD count = GetConsoleProcessList(processes, ARRAYSIZE(processes));
43
44 return (tty != 0) && (count > 1);
45#else
46 return false;
47#endif
48 }
49
50 void release_transient_console()
51 {
52#if defined(_WIN32) && defined(WITH_WIN_CONSOLE)
53 if (has_inherited_console())
54 return;
55
56 if (const HWND hwndConsole = GetConsoleWindow())
57 ShowWindow(hwndConsole, SW_HIDE);
58 (void)FreeConsole();
59#endif
60 }
61 } // namespace win32
62} // namespace sdl