0
votes

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
AFAIK, this is not possible to change a console window's visibility after it's already open. At least not without some hacks. Keep in mind a console window can be used by multiple different applications, and the user can even open a command prompt and then open this application from there.Jerry Dodge
@JerryDodge - you can of course. it is a window. see link.Z80
Like I said, at least not without some hacks :-) Seems really fishy. What if I were to open your application manually from a command prompt? It would be using the console window which was already open, in which case the window doesn't belong to this application.Jerry Dodge

1 Answers

1
votes
  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.