且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++禁止显示命令提示符

更新时间:2022-11-02 23:17:49

配置编译器或链接器将程序标记为GUI应用程序。

Configure your compiler or linker to mark your program as a GUI application.

Windows可识别两种主要类型的程序:GUI和控制台。如果EXE头被标记为控制台程序,则操作系统在执行它之前创建一个控制台窗口。否则,它不。这不是你可以在运行时控制;您需要在链接时设置它。 (你可以调用 ShowWindow(GetConsoelWindow(),SW_HIDE)尝试在运行时控制它,但这不会阻止窗口闪烁然后再关闭。此外,如果您的程序正在与另一个程序共享控制台,如cmd.exe,那么您只是隐藏了用户的命令提示符窗口!)即使您的程序没有任何实际的GUI,仍然是模式需要避免为您创建一个控制台窗口。

Windows recognizes two main types of programs: GUI and console. If the EXE header is marked as a console program, then the OS creates a console window prior to executing it. Otherwise, it doesn't. This isn't something you can control at run time; you need to set it at link time. (You can call ShowWindow(GetConsoelWindow(), SW_HIDE) to try to control it at run time, but that doesn't prevent the window from flickering on and then off again. Plus, if your program is sharing the console with another program, like cmd.exe, then you'll have just hidden the user's command-prompt window!) Even if your program doesn't have any actual GUI, that's still the mode you need to avoid having a console window created for you.

如果您在Visual Studio中启动一个新项目,请选择Win32控制台应用程序选项。如果您已经有一个项目,那么在项目的配置属性中,找到链接器/系统部分的Subsystem设置,并将其设置为控制台。这使得链接器使用 / subsystem:console 选项。如果您使用Mingw,请使用 -Wl, - subsystem,windows 选项。

If you're starting a new project in Visual Studio, select the "Win32 Console Application" option. If you already have a project, then in your project's configuration properties, find the "Subsystem" setting of the "Linker/System" section and set it to "Console." That makes the linker use the /subsystem:console option. If you're using Mingw, use the -Wl,--subsystem,windows option.