I want to write one c++ program, compiling and linking .cpp gives .exe file. if i double click on that and execute it a console gets opened and closed. I don't want that console to appear at all. Please Help.
"SW_HIDE" hides the window, while "SW_SHOW" shows the window.
-mwindows. This option is available for Cygwin and MinGW targets. It specifies that a GUI application is to be generated by instructing the linker to set the PE header subsystem type appropriately.
There are two ways for a Windows program to produce a console window:
The program is linked as a console subsystem exe, which is a request to Windows to always provide an associated console window.
The program's code itself creates a console window.
The first option, console subsystem, is by far most likely.
With the MinGW g++ compiler just add the option
-mwindows
With the Visual C++ compiler, if you're compiling from the command line, add the options
/link /subsystem:windows /entry:mainCRTStartup
If you're using Visual Studio, change the subsystem to windows and change the entry point to mainCRTStartup
in the linker options.
With Microsoft's compiler it can be easier to just link with a module that contains a WinMain
function that itself is a non-standard startup function, and that in violation of the C++ standard calls the ordinary standard main
. That's because with GUI subsystem (subsystem "windows") Microsoft's compiler, as opposed to e.g. g++, does not by default recognize a standard main
. It is simply a Microsoft thing (presumably it started as a vendor lock-in thing).
If you want to create a console type program with a hidden console, then make this the first line of your main routine:
ShowWindow( GetConsoleWindow(), SW_HIDE );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With