Ardour  9.0-pre0-582-g084a23a80d
win_console.h
Go to the documentation of this file.
1 /* STATIC FUNCTIONS -- INCLUDE DIRECTLY BEFORE main () */
2 
3 #if (!defined COMPILER_MSVC && defined PLATFORM_WINDOWS)
4 #include <windows.h>
5 
6 static FILE* pStdOut = 0;
7 static FILE* pStdErr = 0;
8 static BOOL bConsole;
9 static HANDLE hStdOut;
10 
11 static bool
12 IsAConsolePort (HANDLE handle)
13 {
14  DWORD mode;
15  return (GetConsoleMode(handle, &mode) != 0);
16 }
17 
18 static void
20 {
21  bConsole = AttachConsole(ATTACH_PARENT_PROCESS);
22  hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
23 
24  /* re-attach to the console so we can see 'printf()' output etc.
25  * for MSVC see gtk2_ardour/msvc/winmain.cc
26  */
27 
28  if ((bConsole) && (IsAConsolePort(hStdOut))) {
29  pStdOut = freopen( "CONOUT$", "w", stdout );
30  pStdErr = freopen( "CONOUT$", "w", stderr );
31  }
32 }
33 
34 static void
36 {
37  if (pStdOut) {
38  fclose (pStdOut);
39  }
40  if (pStdErr) {
41  fclose (pStdErr);
42  }
43 
44  if (bConsole) {
45  // Detach and free the console from our application
46  INPUT_RECORD input_record;
47 
48  input_record.EventType = KEY_EVENT;
49  input_record.Event.KeyEvent.bKeyDown = TRUE;
50  input_record.Event.KeyEvent.dwControlKeyState = 0;
51  input_record.Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
52  input_record.Event.KeyEvent.wRepeatCount = 1;
53  input_record.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
54  input_record.Event.KeyEvent.wVirtualScanCode = MapVirtualKey( VK_RETURN, 0 );
55 
56  DWORD written = 0;
57  WriteConsoleInput( GetStdHandle( STD_INPUT_HANDLE ), &input_record, 1, &written );
58 
59  FreeConsole();
60  }
61 }
62 
63 #elif (defined(COMPILER_MSVC) && defined(NDEBUG) && !defined(RDC_BUILD))
64 
65 // these are not used here. for MSVC see gtk2_ardour/msvc/winmain.cc
66 static void console_madness_begin () {}
67 static void console_madness_end () {}
68 
69 #else
70 
71 static void console_madness_begin () {}
72 static void console_madness_end () {}
73 
74 #endif
GTKMM_API const Gtk::BuiltinStockID FILE
static void console_madness_begin()
Definition: win_console.h:71
static void console_madness_end()
Definition: win_console.h:72