In Windows, a C++ program can hide or show its console window using functions provided by the Windows API. This can be useful when a program needs to temporarily hide the console while continuing its execution.
- ShowWindow() controls the visibility of a window.
- FindWindowA() is used to obtain the handle of the console window.
Example: The following program displays a countdown, hides the console window, performs another countdown, and then shows the console again.
#include <iostream>
#include <windows.h>
using namespace std;
void countdown()
{
cout << "3" << endl;
Sleep(1000);
cout << "2" << endl;
Sleep(1000);
cout << "1" << endl;
Sleep(1000);
cout << "0" << endl;
}
int main()
{
countdown();
HWND window;
AllocConsole();
// You Can Find HANDLE of other windows too
window = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(window, 0);
countdown();
ShowWindow(window, 1);
}
Output:

Explanation
- countdown() prints numbers from 3 to 0, with a one-second delay between each number.
- AllocConsole() creates a console window, while FindWindowA() gets its handle.
- ShowWindow(window, 0) hides the console window.
- The second countdown() runs while the console is hidden.
- ShowWindow(window, 1) shows the console window again.
Note: This program uses the Windows API and therefore works only on Windows.