views:

2173

answers:

5

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

However, I would like to keep the application minimized most of the time, and instead of minimizing to the taskbar, appear as a nice icon on the system tray. I would also like to restore the console when the system tray icon is clicked.

How should I change my program to do this?

+11  A: 

This is going to be an ugly hack.

First, you have to retrieve the hWnd / hInstance of you console application. Right now, I can only come up with one way:

  • Create a Guid with CoCreateGuid()
  • Convert it to a string
  • Set the title of the console window to this guid with SetConsoleTitle()
  • Find the hWnd of the your window with the Guid as the tile with FindWindow()
  • And you can do it from the usual way from this point. See http://www.gidforums.com/t-9218.html for more info.
  • Don't forget the rename your console window to the original title once you're done.

As you can see, even though this is possible to do, it's a horrible and painful solution. Please don't do it. Please do not minimize console applications to the system tray. It is not something you are supposed to be able to do in the Windows API.

DrJokepu
Dear god that's awful :)
OJ
Interesting Application of a GUID :)
peterchen
agree on the ugly, still an awesome answer, thanks +1
Daniel T. Magnusson
+4  A: 

You might want to write a separate gui to function as a log reader. You will then find it much easier to make this minimize to the tray. It would also let you do some other stuff you might find useful, such as changing which level of logging messages are visible on the fly.

Colin Pickard
A: 

Probably your best bet is to create a "Message-only window" (a message queue without a visible window) to receive the Notification Area messages.

MSalters
A: 

The answer with a GUID is completely ridiculous (no sense at all) The Console hWnd is of course given by GetConsoleWindow() (!)

+1  A: 
IMarosi