Win32 编程隐藏控制台窗口
我正在学习 C++,并制作了一个新程序.我删除了一些代码,现在我的控制台窗口没有隐藏.有没有办法让它在启动时隐藏而不让他们看到?
I'm learning C++ and I made a new program. I deleted some of my code and now my console window is not hidden. Is there a way to make it hide on startup without them seeing it?
推荐答案
如果你正在编写一个控制台程序,并且你想断开你的程序与它开始的控制台的连接,那么调用 FreeConsole
.最终,您可能不会对该函数的实际功能感到满意,但这就是您所问问题的字面答案.
If you're writing a console program and you want to disconnect your program from the console it started with, then call FreeConsole
. Ultimately, you probably won't be satisfied with what that function really does, but that's the literal answer to the question you asked.
如果您编写的程序一开始就不想拥有控制台,那么请配置您的项目,使其不是控制台程序.控制台"是 EXE 文件的一个属性.操作系统读取该设置并决定是否在您的任何代码运行之前为您的程序分配一个控制台,因此您无法在程序中控制它.有时,非控制台程序称为GUI 程序",因此您可能会在开发环境的配置选项中寻找控制台"和GUI"之间的选择.不过,将其设置为 GUI 并不要求您有任何用户界面.该设置仅控制您的程序是否以控制台启动.
If you're writing a program that you never want to have a console in the first place, then configure your project so that it is not a console program. "Consoleness" is a property of the EXE file. The OS reads that setting and decides whether to allocate a console for your program before any of your code ever runs, so you can't control it within the program. Sometimes a non-console program is called a "GUI program," so you might look for a choice between "console" and "GUI" in the configuration options of your development environment. Setting it to GUI doesn't require that you have any user interface at all, though. The setting merely controls whether your program starts with a console.
如果您正在尝试编写一个有时可以有控制台而有时没有的程序,那么请参阅之前的问题,一个可执行文件可以既是控制台应用程序又是 GUI 应用程序吗?
If you're trying to write a program that can sometimes have a console and sometimes not, then please see an earlier question, Can one executable be both a console and GUI app?
相关文章