| 7 | #include <windows.h> |
| 8 | |
| 9 | void MainWindow::toggleConsole() { |
| 10 | if (actionToggleConsole->isChecked()) { |
| 11 | // If the console is created from opening up the EXE in |
| 12 | // Explorer, the console will be completely destroyed once the |
| 13 | // console is hidden/freed. Therefore, we need to check for |
| 14 | // that, and create a new console if necessary. On the other |
| 15 | // hand, if we spawned this process from an existing console, |
| 16 | // AttachConsole will still work! |
| 17 | if (!AttachConsole(ATTACH_PARENT_PROCESS)) { |
| 18 | if (!AllocConsole()) { |
| 19 | QMessageBox::critical(this, "Error", "Unable to open console."); |
| 20 | } |
| 21 | } |
| 22 | SetConsoleOutputCP(CP_UTF8); |
| 23 | } else { |
| 24 | if (!FreeConsole()) { |
| 25 | QMessageBox::critical(this, "Error", "Unable to close console. If you are running directly from a console, you may not be able to close it."); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | m_config->setValue(SETTING_ENABLE_WIN_CONSOLE, actionToggleConsole->isChecked()); |
| 30 | } |
| 31 | |
| 32 | void MainWindow::installToggleConsole() { |
| 33 | // Build menu option and add it! |
nothing calls this directly
no outgoing calls
no test coverage detected