Rafo 554
Rafo 554

Reputation: 109

Hide console before console appear C++

How to run a C++ code, without console ?

ShowWindow(GetConsoleWindow(), SW_HIDE); hide the window, but after it apear.

Before run the program, can I put a line witch hide completly console ?

Upvotes: 5

Views: 293

Answers (1)

Fabio Crispino
Fabio Crispino

Reputation: 731

You can set this pragma inside the file where main method is located, on top of your header files includes:

#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")

This can also be done with linker options:

/SUBSYSTEM:windows
/ENTRY:mainCRTStartup

As alternative, in VS, change the project subsystem to Windows (/SUBSYSTEM:WINDOWS) in Project Properties-Linker-System-Subsystem. If you do that, use the WinMain signature instead of main signature:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
    // Your code here.
    return 0;
}

Subsystem settings.

Upvotes: 3

Related Questions