問題描述
我正在學習 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?
這篇關于Win32 編程隱藏控制臺窗口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!