A second clock in the Windows tray?
Friday, 22. June 2007, 06:05:31
You could of course just open up google and look up a page with the time for the place or change the windows timezone temporarily so the clock would show the correct time there...
But that's kind of annoying and time consuming, so I came up with a solution: Display a second configurable clock in the system tray!
Problem
So what do we need? Only a little bit of C# code and a vision.
I had this simple idea: Since an application can display an icon in the tray, why not just display two icons instead of one - Hours in the first icon, minutes in the second icon.
All you need to do is generate some icons on the run for the numbers and make sure they show next to each other in the tray, in the correct order. A simple interface for changing the hour and minute offset would be useful too.
Solution
Creating an interface is easy in Visual Studio 2005. The icon generation and ordering in the tray was the only small challenge.
I found out you can easily generate icons by creating a Bitmap on the run in the app. Just draw some numbers to it and use Icon.FromHandle(bitmap.GetHicon()).
Getting the icons show up in the correct order was equally simple: You just need to toggle their visibility in the tray off and then back on again in the correct order.
Files
As usual, here are both the source code and the executable file for the application.
TrayClock executable (zip, 5kB)
TrayClock source (zip, 13kB)
When you start the program, you get the configuration screen where you can set the offset from current time. Add a - in the front for negative offset. After setting the time you can hide the configuration screen by clicking the minimize icon. To get back into the configuration, just doubleclick on either of the icons in the tray.
I've tested the program and it runs fine for hours and hours - until the screensaver kicks in, which will cause the icons in the tray to disappear because of a GDIException which I was unable to solve... You just have to restart it after that or if you can fix it, let me know!








drlaunch # 22. June 2007, 07:48
And I was told to contact you!
So gimme it!
zomg # 22. June 2007, 07:53
.NET Framework 2.0 is what you need to run it.
drlaunch # 22. June 2007, 07:57
And it's because I haven't ran the regular Windows update yet, I think. So I've gotten only security updates.
Anonymous # 30. May 2008, 20:08
your clock has a problem after i add one more icon "seconds" in and put timer interval to 250. it disappears after a while and after i take away the catch try code in "CreateIcon", it gives me this error message:
A generic error occurred in GDI+
Anonymous # 20. February 2009, 10:27
Here is a GDI+ memory leak: Icon.FromHandle(bitmap.GetHicon()).