As @Cheers and hth. -Alf points out in the comments, you can simply make a GUI application with no window instead of a console application. Since you’re using Windows, you can change your code from:
int main()
to:
#include <Windows.h>
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
You’ll need to change your linker options. You can do this by following the instructions on the answer provided (also by @Cheers and hth. -Alf) to this question:
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.
For CodeBlocks, a very quick Google search revealed the following answer:
- Click Project on the CodeBlocks menu.
- Click Properties.
- Click the second tab, Build Targets.
- On the right, where it says Type: Console application, change it to GUI application.
- Rebuild the project.
Your application will no longer make a window.
2
solved How can I run an exe file without the user finding out?