如何显示/隐藏控制台窗口应用程序? [英] How to show/hide a console window app?
问题描述
我有一个小型控制台应用程序。当我从主程序中调用它时,我想隐藏它的窗口(使用-hide作为命令行参数),并在用户启动它时显示它的窗口(没有命令行参数)。
I have a small console app. I want to hide its window when it is called from my main program (with -hide as command line parameter) and show it when the user starts it (no command line param).
此问题建议使用{$ APPTYPE GUI}而不是{$ APPTYPE CONSOLE}将隐藏窗口。确实有效。但是,当用户运行时,如何使窗口可见?
This question suggests that using {$APPTYPE GUI} instead of {$APPTYPE CONSOLE} will hide the window. And indeed it works. But how do I make the window visible when ran by user?
目的:我希望我的主程序在后台与控制台应用程序进行静默交互(控制台不可见) 。因此,当用户单独启动控制台应用程序时,我只想向他发出警告:‘该控制台应用程序正在执行x任务。您无法手动启动它。
Purpose: I want my main program to interact with the console app silently in the background (console is invisible). So, when the user starts the console app alone, I just want to give him a warning: 'This console app is doing x task. You cannot start it manually'.
推荐答案
- 将程序作为控制台应用程序保留下来。不要将其放入GUI应用程序中,因为这意味着用户直接启动它时,将不会获得控制台。
- 从主应用程序启动程序时,请使用
CreateProcess
为此,传递CREATE_NO_WINDOW
标志。该标志确保不会创建任何控制台窗口。
- Leave the program alone, as a console application. Do not make it into a GUI application because that means that when users start it directly, it will not be given a console.
- When you start the program from your main app, use
CreateProcess
to do so, passing theCREATE_NO_WINDOW
flag. That flag ensures that no console window will be created.
这篇关于如何显示/隐藏控制台窗口应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!