I dont want console to appear when i run c++ program

后端 未结 7 788
时光取名叫无心
时光取名叫无心 2021-02-07 11:24

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

相关标签:
7条回答
  • 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);
    
    0 讨论(0)
  • 2021-02-07 11:41

    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.

    0 讨论(0)
  • 2021-02-07 11:45

    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);
    
    0 讨论(0)
  • 2021-02-07 11:45

    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
    
    0 讨论(0)
  • 2021-02-07 11:50

    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 );
    
    0 讨论(0)
  • 2021-02-07 11:52

    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);

    0 讨论(0)
提交回复
热议问题