简体   繁体   中英

Visual c++ Hide Console Windows

I'm making an updater for my app. My app is a UI application. I want to make it as a console application but I don't know how to hide it. I used this code:

HWND hwnd = GetConsoleWindow();
ShowWindow(hwnd, 0);

But when application runs the cmd windows appears for a second. How can I hide it?

What good is a console window that you proceed to hide (unless you're making a console window replacement, which you are not making)?

The easiest way to hide the console window is to not create it in the first place, ie, simply don't link the exe as a console subsystem executable, but link at as a GUI (aka "windows") subsystem executable.

One consequence of that is that the standard Windows command interpreter won't wait for the program to finish, but that's all.


Another option is to run your program via a utility that starts it with the console window hidden. VBScript and Windows Script Host come to mind. But this would be a relatively speaking extreme complication in order to suppress a window that is only there because you've asked for it...

FreeConsole() API将为您做到这一点:

BOOL WINAPI FreeConsole(void);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM