Question

With the code below, the console is hidden BUT it appears for about 1 second.

How can I completely hide the console ?

#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>

using namespace std;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow){

HWND hWnd = GetConsoleWindow();
ShowWindow( hWnd, SW_HIDE );

MessageBox(NULL, TEXT("Hello!"), TEXT("yuhuuu"), 0);
return 0;
}
Was it helpful?

Solution

Something is weird with your compiler settings. (You did not specify your compiler so I'm assuming MSVC)

The WinMain entry point function from your example is used by GUI applications (Linker switch /SUBSYSTEM:WINDOWS) and those applications don't get a console unless you call AllocConsole.

If you link with /SUBSYSTEM:CONSOLE then Windows will create a console for the process before your code is executed but a normal entry point for those applications is the plain old main function.

Are you forcing the entry point with the /ENTRY switch? Either way, make sure the /SUBSYSTEM switch and the entry point function definition are compatible and match the type of application you want to create (GUI or console)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top