Search code examples
c++netbeanswinmain

Console is still shown with WinMain entry point in C++ using Netbeans


I'm trying to make a small application which starts another application depending on command line parameters.

I am using the WinMain entry point like this:

BOOL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR commandLine, int nCmdShow) {
    ...
}

but I still see a console window.

How can I make sure that the no console window is ever drawn when running the application?

  1. How to configure Netbeans in order to do so?
  2. Do I have to change abovementioned code? If yes, what must be changed or added?

PS: I can hide the console window with ShowWindow(GetConsoleWindow(), SW_HIDE), but you still see the console window for a fraction of a second. I want to make sure that the console window is never shown.


Solution

  • The code is fine. The compiler flag -mwindows will do the trick.

    To set the compiler flag do the following:

    1. Right-click your project, click Properties
    2. Click on C++ Compiler in the category Build
    3. Add -mwindows in the line Additional Options
    4. Click OK and rebuild your project.