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 consol
On CODEBLOCKS, besides what @ravenspoint said, you have to put this line on your first line of code:
#define _WIN32_WINNT 0x0501 //this is for XP
And then:
ShowWindow (GetConsoleWindow(), SW_HIDE);
It sounds like you need to update your Windows Visual Studio project settings to not be a console app.
If this isn't the case, then please post more information about your environment and tools.
If you can't move to a Window application (I mean with GUI) because sometimes you may need to use the console for output you can use following code to hide the console window:
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE);
make sure you define _WINDOWS
or WINDOW
during compile and linking. (depending on your environment).
On the commandline you can do this as follows
cl -D_WINDOWS program.cpp
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 );
Weaker preconditions:
If your program does not have console child processes, simply
FreeConsole();
should do it.
Else
a (hidden) window is required in order to not have console popups from child processes, i.e. as mentioned above
ShowWindow (GetConsoleWindow(), SW_HIDE);