Search code examples
c++windowswxwidgets

How can one hide the console window of a Windows program?


I am using the wxWidget framework. When I set System/Subsystem: Console (/SUBSYSTEM:CONSOLE) then my program will start but will show both a GUI and a console. This is how it looks: https://i.sstatic.net/G83PR.png

When I change System/Subsystem: Windows (/SUBSYSTEM:WINDOWS) then it show errors:

LNK2019 unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

This is my code:

int main(int argc, char** argv) {
    Gui_AutoPokemon* gui = new Gui_AutoPokemon();
    wxApp::SetInstance(gui);

    mainArgc = argc;
    mainArgv = argv;

    return wxEntry(argc, argv);
}

How can I hide the console window?


Solution

  • GUI Windows programs use a different entry point function than console. You're right to use /SUBSYSTEM:WINDOWS, but then you need to change to using WinMain:

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR cmdLine, int nCmdShow) {
        ....
    

    Then use the appropriate wxEntry overload:

    return wxEntry(hInstance, NULL, cmdLine, nCmdShow);