C ++禁止显示命令提示符 [英] C++ disallow command prompt from displaying

查看:164
本文介绍了C ++禁止显示命令提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么我可以做的,以确保shell /命令提示符没有显示当我运行我的C ++程序,它的意思是一个后台程序?虽然这不是一个巨大的交易,如果它显示,因为它很快关闭,我宁愿它根本不显示。程序将运行在windows xp / vista / 7操作系统

Is there any thing I can do to make sure that the shell/command prompt does not show up when I run my C++ program, it is meant to be a background program? While it isn't a huge deal if it displays because it quickly closes, I would prefer it doesn't display at all. Program will run on windows xp/vista/7 OS

推荐答案

配置编译器或链接器将程序标记为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.

这篇关于C ++禁止显示命令提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆