Click here to Skip to main content
15,616,990 members
Articles / Desktop Programming / MFC
Posted 29 May 2003


82 bookmarked

XTimer - Timer and Stopwatch Utility with Source Code

Rate me:
Please Sign up or sign in to vote.
4.81/5 (33 votes)
20 Aug 2007CPOL3 min read
XTimer provides countdown timer and stopwatch features in a compact MFC dialog app.


XTimer is a useful tool for measuring time durations - for example, if you want to measure how long it takes for a program to run. XTimer offers these features:

  • Countdown timer - counts down (like a microwave oven timer) from some HH:MM:SS value to zero.
  • Stopwatch - continuously counts up until stopped.
  • Play a wav file - when the countdown timer expires, XTimer will optionally play a wav file.
  • Compact size - takes very little space on the desktop.
  • Play once/Play until stopped - play the sound only once, or play it continuously (every 30 seconds) until the Stop button is clicked.

XTimer User Interface

Main Window


There are three buttons on the main window: Start, which starts the timer/stopwatch and then changes to Stop; Reset, which sets the timer back to the zero position; and More, which displays the context menu (the context menu is also displayed by right-clicking on the window).

Context Menu


The context menu allows you to choose the XTimer mode - stopwatch or countdown timer. When you change mode, the XTimer caption changes to reflect the mode you have set. You can also access the Timer Options Dialog.

The Quick Timer sub-menu allows you to choose a time for the countdown timer, and will also automatically start the timer.

Timer Options Dialog


The Timer Options Dialog allows you to set the countdown time and the wav file to be played when the timer expires. If the Play Countdown Timer Sound is checked but no wav file is selected, XTimer will play its default sound. To completely disable all sounds, uncheck Play Countdown Timer Sound.

You can choose to play the sound only once, or play it continuously (every 30 seconds) until the Stop button is clicked. If the Play until stopped option is selected, the caption will change to XTimer [TIMER+].

Using XTimer

XTimer.exe is self-contained and needs no other files (besides the standard MFC and system DLLs). After selecting the mode (and for the timer, the countdown time and sound options), click Start. The stopwatch/timer will begin running, and the Start button will change to Stop. If you click on the Stop button, it will change back to Start and the timer will stop running. The display will hold the last value displayed and will continue from the last value if you click on the Start button.

XTimer saves its settings to the registry in HKEY_CURRENT_USER\Software\CodeProject\XTimer.


Revision History

Version 1.3 - 2007 August 11

  • Save program options in registry
  • Left double-click on time display opens options dialog
  • Added Quick Timer sub-menu
  • Added VS2005 project

Version 1.2 - 2003 June 16

  • Fixed display bug reported by Pit M.

Version 1.1 - 2003 June 14

  • Added "Play once, Play until stopped" option

Version 1.0 - 2003 June 1

  • Initial public release


This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see

Comments and Discussions

QuestionHow to... Pin
silvrsurfr10-Sep-17 8:23
silvrsurfr10-Sep-17 8:23 
GeneralBrilliant. Thankyou Pin
SleepyBoBos16-Sep-08 18:31
SleepyBoBos16-Sep-08 18:31 
GeneralShow in TaskBar Pin
Priyank Bolia29-Aug-07 21:19
Priyank Bolia29-Aug-07 21:19 
GeneralTray Icon suggestion [modified] Pin
yarp21-Aug-07 22:13
yarp21-Aug-07 22:13 
GeneralBut Hans! My tea needs 3 minutes, no more, no less! Pin
peterchen21-Aug-07 2:32
peterchen21-Aug-07 2:32 
GeneralRe: But Hans! My tea needs 3 minutes, no more, no less! Pin
Hans Dietrich21-Aug-07 10:40
mentorHans Dietrich21-Aug-07 10:40 
GeneralExcellent job Pin
tnov12-Jul-07 5:02
tnov12-Jul-07 5:02 
GeneralNew Features [modified] Pin
Bassam Abdul-Baki3-Mar-07 8:30
professionalBassam Abdul-Baki3-Mar-07 8:30 
GeneralFeatures Request...! Pin
ana_v12327-Sep-06 17:13
ana_v12327-Sep-06 17:13 
GeneralRe: Features Request...! Pin
KJJ27-Nov-06 3:18
KJJ27-Nov-06 3:18 
GeneralStopwatch for Borland c++ Pin
Member 229052720-Sep-05 9:03
Member 229052720-Sep-05 9:03 
Generalgood job Pin
Anonymous30-Oct-04 2:48
Anonymous30-Oct-04 2:48 
GeneralReally Good work :-) Pin
Pit M.16-Jun-03 20:00
Pit M.16-Jun-03 20:00 
GeneralRe: Really Good work :-) Pin
Hans Dietrich16-Jun-03 21:02
mentorHans Dietrich16-Jun-03 21:02 
GeneralRe: Really Good work :-) Pin
Pit M.16-Jun-03 22:30
Pit M.16-Jun-03 22:30 
GeneralRe: Really Good work :-) Pin
Hans Dietrich17-Jun-03 2:05
mentorHans Dietrich17-Jun-03 2:05 
GeneralRe: Really Good work :-) Pin
Pit M.17-Jun-03 2:39
Pit M.17-Jun-03 2:39 
GeneralCool... Good idea Pin
Joel Holdsworth30-May-03 21:45
Joel Holdsworth30-May-03 21:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.