Skip to content

Instantly share code, notes, and snippets.

@opsJson
Last active December 25, 2021 23:22
Show Gist options
  • Select an option

  • Save opsJson/b0266efba72986dc0fcbf67e694daf75 to your computer and use it in GitHub Desktop.

Select an option

Save opsJson/b0266efba72986dc0fcbf67e694daf75 to your computer and use it in GitHub Desktop.
Re-enable console for win32 apps, or hide console for console apps.
#include <stdio.h>
#include <windows.h>
char SHOW_FLAG = 0;
void console_show() {
AllocConsole();
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
SHOW_FLAG = 1;
}
void console_hide() {
HWND window;
AllocConsole();
window = FindWindow("ConsoleWindowClass", NULL);
if (window) ShowWindow(window, 0);
}
/*///////////////////////////////////
Testing:
///////////////////////////////////*/
int main() {
console_show();
printf("foo!\n");
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment