Multiple Clocks

Introduction

This dialog-based application displays several different styles of clocks: analog, binary, decimal, and nixie.

Background

The Nixie tube was used in electronic instruments mainly in the 1960s thru 1980s. It is a neon-filled vacumn tube with 10 elements that can make the neon glow when any one element is grounded. The tube has a common anode with approximately 175 volts DC applied to it. I think it makes a cool clock.

Using the Code

Several methods used in this code are borrowed from other programmers, some from this site (see Credits). The heart of the binary clock is the _itoa(nTime, ibuff, 2); function, where nTime is any integer contaning the hour, minute, or second. ibuff is a char buffer and the 2 is a base, in this case, binary.

Here is the code to display a simple Decimal clock in the Windows Title Bar.

void CMultiClockDlg::DisplayDecimal()
{
   //
   // Get the current time
   //
   CTime time  = CTime::GetCurrentTime();
   int nSecond = time.GetSecond();
   int nMinute = time.GetMinute();
   int nHour   = time.GetHour();
   if (nHour > 12)
      nHour -= 12;
   CString szStr;
   szStr.Format("MultiClock - %.2d:%.2d:%.2d", nHour, nMinute, nSecond);
   ::SetWindowText(m_hWnd, szStr);
}

Points of Interest

The Binary display is grouped: 4 bits for the hour, and 6 bits for the minutes and seconds. I did this because the hour can only be "01" thru "C" and the minutes/seconds "00" thru "3B". The nixie clock uses bitmaps (45X64) for each digit; they are diplayed by calling:

void CMultiClockDlg::FormatTm(CDC *pDC, int nTime, int nPos)
{
   int x, y;
   m_bmp.LoadResource(IDB_BITMAP110);
   x = 8 +(m_bmp.GetWidth() * nPos);
   y = 8;
   switch (nTime)
   {
      case 0:
         m_bmp.LoadResource(IDB_BITMAP100);
         m_bmp.DrawDIB(pDC, x, y);
         break;
   }

One thing I found when writing this code was this: DO NOT USE CDC *pDC = GetDC(); in a loop without using RelaseDC(pDC); My first version would run for 15 to 20 minutes and crash because GetDC() uses 4 bytes of memory every time it is called.

Credits

ClockCtrl—The Analog Clock
Author: P.J. Naughter

Dib256—Load Resource/Paint Bitmap
DibPal
Author: Jorg Konig

History

Version 1.0
Any comments or suggestions are welcome.



Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds