int setup_console () { #if defined (_WIN) SetConsoleWindowSize (132); if (_setmode (_fileno (stdin), _O_BINARY) == -1) { __mingw_fprintf (stderr, "%s: %m", "stdin"); return -1; } if (_setmode (_fileno (stdout), _O_BINARY) == -1) { __mingw_fprintf (stderr, "%s: %m", "stdin"); return -1; } if (_setmode (_fileno (stderr), _O_BINARY) == -1) { __mingw_fprintf (stderr, "%s: %m", "stdin"); return -1; } #endif return 0; }
void console::OpenHideConsole() { HWND hWnd = GetConsoleWindow(); if (hWnd!=NULL) { if (IsWindowVisible(hWnd)) ShowWindow( hWnd, SW_HIDE ); else ShowWindow( hWnd, SW_SHOW ); EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED); return; } // create a console window AllocConsole(); // SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12); //display in red ;) EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED); HWND hwnd = GetConsoleWindow(); HMENU hmenu = GetSystemMenu (hwnd, FALSE); //HINSTANCE hinstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE); while (DeleteMenu (hmenu, 0, MF_BYPOSITION)) ; // redirect std::cout to our console window m_old_cout = std::cout.rdbuf(); m_out.open("CONOUT$"); std::cout.rdbuf(m_out.rdbuf()); // redirect std::cerr to our console window m_old_cerr = std::cerr.rdbuf(); m_err.open("CONOUT$"); std::cerr.rdbuf(m_err.rdbuf()); // redirect std::cin to our console window m_old_cin = std::cin.rdbuf(); m_in.open("CONIN$"); std::cin.rdbuf(m_in.rdbuf()); SetConsoleWindowSize(140, 30); SetConsoleTitle("Domoticz Home Automation System"); }