How to write a console application in Windows that is minimized to the system tray?

I have a written Visual C ++ console application (i.e. subsystem: console) that prints useful diagnostic messages to the console.

However, I would like the application to be minimized most of the time and instead of minimizing it, the taskbar would appear as a good icon on the taskbar. I would also like to restore the console when I click on the icon in the system tray.

How do I change my program for this?

+4
source share
5 answers

It will be an ugly hack.

First you should get hWnd / hInstance console application. Right now I can only approach one way:

  • Create a guide using CoCreateGuid()
  • Convert it to string
  • Set the console window title to this guide using SetConsoleTitle()
  • Find the hWnd your window using Guid as tiles with FindWindow()
  • And you can do it from the usual path from now on. See http://www.gidforums.com/t-9218.html for more details.
  • Remember to rename the console window to its original name after completion.

As you can see, although this can be done, this is a terrible and painful decision. Please do not do this. Do not collapse console applications onto the system tray. This is not what you should do in the Windows API.

+14
source

You might want to write a separate gui to work as a log reader. After that, it will be much easier for you to do this reduction to the tray. It will also allow you to do some other things that you might find useful, such as changing the level of log messages on the fly.

+4
source

To find out the hWnd console, you have two options:

  • In Windows 2000 or later, you can use the GetConsoleWindow () function. Remember to specify _WIN32_WINNT as 0x0500 or higher before enabling windows.h to access this feature.
  • If you want to run your program on earlier versions of Windows, then you should use something like the GUID trick described above.
+1
source

It is probably best to create a "Message Only Window" (message queue without a visible window) to receive a Notification area message.

0
source

The answer with the GUID is completely ridiculous (it makes no sense at all) The hWnd console, of course, is provided by GetConsoleWindow () (!)

0
source

All Articles