How to show/hide a console window app?

这一生的挚爱 提交于 2019-12-25 07:46:55

问题


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).

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?

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'.


回答1:


  1. 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.
  2. When you start the program from your main app, use CreateProcess to do so, passing the CREATE_NO_WINDOW flag. That flag ensures that no console window will be created.


来源:https://stackoverflow.com/questions/42767078/how-to-show-hide-a-console-window-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!