Skip navigation

Sign up | Lost password? | Help

Hello World

Practical programming... and stuff...

A second clock in the Windows tray?

,

Since I talk with many people who aren't finnish, I've sometimes had some problems with their timezones and such. You know, sometimes it's useful to know what time it is somewhere else.

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!

Funny Windows 2000 translation mistakeThe power of standards

Comments

drlaunch 22. June 2007, 07:48

Nice. I need to install a version of the .NET framework. :smile:

And I was told to contact you! :D

So gimme it! :lol:

zomg 22. June 2007, 07:53

What where when? Since when do the apps say to contact me o_O

.NET Framework 2.0 is what you need to run it.

drlaunch 22. June 2007, 07:57

It's the usual error message people who are missing .NET framework 2 gets when they try to run such an app.

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

Anonymous writes:

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

Anonymous writes:

Here is a GDI+ memory leak: Icon.FromHandle(bitmap.GetHicon()).

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies