在 C++ 中隐藏黑色窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8945018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hiding the black window in C++
提问by dsynkd
Possible Duplicate:
Create an Application without a Window
Win32 programming hiding console window
How can I hide the console window that appears when I run my C++ program? The program doesn't output anything to stdout, and I don't need that black window to appear each time I run the program. I don't want it to be minimized I want it to be invisible. Any ideas?
如何隐藏运行 C++ 程序时出现的控制台窗口?该程序不会向标准输出输出任何内容,并且每次运行该程序时我都不需要出现那个黑色窗口。我不希望它最小化,我希望它不可见。有任何想法吗?
回答by parapura rajkumar
If you want to hide the console you can call FreeConsoleon windows
如果你想隐藏控制台,你可以在 Windows 上调用FreeConsole
#include <Windows.h>
int main()
{
FreeConsole();
//other stuff
}
As David mentioned this might flash for a brief second. If you don't want that you can create a windows serviceor a windows gui application and not create a window like below
正如大卫所提到的,这可能会闪烁一秒钟。如果你不想要,你可以创建一个windows 服务或 windows gui 应用程序,而不是创建一个像下面这样的窗口
#include <windows.h>
int WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
//do stuff here
return 0;
}
回答by David Heffernan
It sounds like the problem is that you are creating a console application. These come with a console by default. They either inherit the console of the process that called them, if it has one, or otherwise create a new console.
听起来问题在于您正在创建一个控制台应用程序。默认情况下,它们带有一个控制台。它们要么继承调用它们的进程的控制台(如果有的话),要么创建一个新的控制台。
You should make your application target the GUI subsystem rather than the console subsystem. This doesn't mean that you have to show any GUI. It's perfectly reasonable and commonplace to make an application that targets the GUI subsytem but does not show any windows.
您应该使您的应用程序面向 GUI 子系统而不是控制台子系统。这并不意味着您必须显示任何 GUI。制作一个针对 GUI 子系统但不显示任何窗口的应用程序是完全合理和常见的。