Many times you want to write programs that execute silently in the background, without the black console window showing. The method of setting entry points found on the Internet does not work. However, by looking at various sources, I found that you can use a built-in API.

You can write a function to hide the window and refer to it in the main function. The contents are as follows:

void HideWindow() { HWND hwnd = GetForegroundWindow(); If (HWND) {ShowWindow(HWND, SW_HIDE); // Set the display status of the specified window}}Copy the code

Note that the program begins with #include

Reference it in the main function, and you can find it!

Complete code:

#include <windows.h>
using namespace std;
 
void HideWindow() {
	HWND hwnd = GetForegroundWindow();
	if (hwnd) {
		ShowWindow(hwnd, SW_HIDE);
	}
}
 
int main() {
	HideWindow();
	system("pause");
}
Copy the code

I used pause, but if you run it, you can’t see it. The program can be found and terminated in task manager.

To sum up is to create HWND object to find the window handle and then set its hidden but not hidden child window can be.

You could write it this way in C, same thing.