How to close a console created with AttachConsole() by a GUI app without exiting the GUI app
I created a Windows GUI app (for example, it has a taskbar icon) that also uses a console. (console as in conhost.exe) Yes, I am aware this doesn't work as well on Windows as it does on Linux. On program launch the app does not create an attached console. One of the menu items of the taskbar icon, however, does allow you to create an attached console. When created, this attached console displays information from the program as it runs. I want to have a way to completely get rid of the console without exiting my app when I am done reading that information. My problem is that if I click the Close button (little "X" on the top right of the window) on the console then both the console AND my app terminate. Right now I am hiding the console window using ShowWindow() WinAPI as a work around but this leaves the console running in the background - i.e. it is visible in Task Manager.
Potential solutions that I am aware of:
1) Create a separate child program that owns the Console. Then send messages from the main app to the child app when I want to write to the console. That way when I completely close the console only the child app will be terminated. Then if I need the console again I can respawn the child app. The downside seems to be that I would need to write and maintain the code for this separate child app and that debugging would become more complicated. Also, I would want to write the child app to automatically close itself if the parent app gets closed which is additional functionality I would need to implement. Basically, this option adds complexity.
2) Use a "fake" console window that merely approximate the visual appearance and behavour of a console but is not actually a console. Unfortunately the examples of these "fake" consoles that I have found online are not great and I don't want to implement one from scratch.
Potential solutions that I am aware of:
1) Create a separate child program that owns the Console. Then send messages from the main app to the child app when I want to write to the console. That way when I completely close the console only the child app will be terminated. Then if I need the console again I can respawn the child app. The downside seems to be that I would need to write and maintain the code for this separate child app and that debugging would become more complicated. Also, I would want to write the child app to automatically close itself if the parent app gets closed which is additional functionality I would need to implement. Basically, this option adds complexity.
2) Use a "fake" console window that merely approximate the visual appearance and behavour of a console but is not actually a console. Unfortunately the examples of these "fake" consoles that I have found online are not great and I don't want to implement one from scratch.
