0

I have a Qt based console application, that has to be located on the Windows System Tray (aka Notification Area).

The question: how can I hide the console window instead of minimizing it if the user clicks on "minimize" icon? I know the ShowWindow method, but as I guess, I have to call it asynchronously.

Kiloreux
  • 2,220
  • 1
  • 17
  • 24

1 Answers1

-2

You need to obtain the HWND window handle of the Console window, then you can use ShowWindow to show or hide it in the usual way.

The question is when do you do this? You need to know when the window is minimised in order to know whether to hide it.

You could check this periodically, but you should be careful to ensure you are not preventing laptops etc. from sleeping by doing so.

Alternatively you could install a message hook, or subclass the window, to recieve immediate notifications.

Subclassing the window is probably the best method.

Ben
  • 34,935
  • 6
  • 74
  • 113
  • Hi, what could be the base class and which methods should be overridden in this case? –  Jan 11 '16 at 14:43
  • @moravas, that's not how Window Subclassing works. This technology has a history which dates from 1985, before C++ was in common use. You need to look up "window subclassing". – Ben Jan 11 '16 at 15:02
  • The console window is not your average window. It is owned by the CSRSS system process and [cannot easily be subclassed](http://stackoverflow.com/q/13371644/1889329). – IInspectable Jan 11 '16 at 19:23
  • Subclassing is far from the best option, it's not an option at all – David Heffernan Jan 11 '16 at 23:04
  • @IInspectable, that answer is out of date. Te console window is owned by conhost.exe and runs in the current user context. Nothing prevents you using a hook, and subclassing can be done once one has injected the DLL containing the code. – Ben Jan 12 '16 at 08:50
  • @DavidHeffernan, why do you say that? – Ben Jan 12 '16 at 14:36
  • The console window is no longer owned by CSRSS since Windows 6.1 (*"Windows 7"*). Since Windows Vista is still officially supported, the answer is anything but out of date. A solution for Windows 7 and above would be to set a [WinEvents](https://msdn.microsoft.com/en-us/library/windows/desktop/dd373889.aspx) hook. Subclassing, polling, or a message hook aren't appropriate solutions. – IInspectable Jan 12 '16 at 15:44