Click here to Skip to main content
Licence 
First Posted 20 Jun 2005
Views 26,869
Bookmarked 17 times

BinClock

By | 20 Jun 2005 | Article
A binary clock with options.

Sample Image

Sample Image

Introduction

This project shows how to convert a decimal number to binary using the subtraction method. It has options to change rectangle colors, hide or display a decimal clock, and to play a clock ticking sound.

Using the code

To sample the system clock in a timer, I have set the timer to 250ms (4 times per second) and compare the current second to a saved value.

void CBinClockDlg::OnTimer(UINT nIDEvent) 
{
    // TODO: Add your message handler code here and/or call default
    CTime time = CTime::GetCurrentTime();
    int nSecond = time.GetSecond();
    if(tTime != nSecond)
        Display();
    tTime = nSecond;

    CDialog::OnTimer(nIDEvent);
}

To convert the decimal value of hours, minutes, and seconds to binary, test if the decimal value is greater than or equal to the binary bit values 32, 16, 8, 4, 2, 1. If so, set the corresponding bit and subtract the bit value from the decimal value.

...
    // Convert decimal to binary
    if (nHour >= 16)
    {
        DisplayHour(5);
        nHour -= 16;
    }
...
    case 5:
        pDC = m_hour5.GetDC();
        m_hour5.GetClientRect(&rect);
        pDC->FillRect(&rect, &m_brush);
        ReleaseDC(pDC);
        break;
...

The ticking sound uses: PlaySound("SOUNDTICK", hInst, SND_RESOURCE | SND_ASYNC); which is defined in Mmsystem.h and included in Winmm.lib. SOUNDTICK is defined in the rc file: "res\\tick.wav".

History

  • 20 June 2005 - Version 1.0.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Roger65



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralA binary clock shouldn't "tick-tock". PinmemberWREY10:22 21 Jun '05  
GeneralRe: A binary clock shouldn't "tick-tock". PinmemberRoger6510:30 21 Jun '05  
GeneralRe: A binary clock shouldn't "tick-tock". PinsussAnonymous3:04 22 Jun '05  
GeneralRe: A binary clock shouldn't "tick-tock". PinsussAnonymous12:47 29 Jun '05  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 21 Jun 2005
Article Copyright 2005 by Roger65
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid