SetTime
by Pete Pinter
Calgary, Alberta, Canada
(updated 96/7/25)
SetTime is a simple Time Protocol (RFC868) client, written
to demonstrate:
- Windows programming in Visual C++
- Microsoft Foundation Classes (MFC)
- WinSock Programming over the Internet
- Dynamically resized Fonts and Buttons
- Memory based Device Contexts (DC)
- Right Mouse Button Menus
- Status Bar Handling
- Graphic Bitmaps as Menu options
- Registry Persistence of Parameters and Options
- Basic GDI Graphics Operations
- Basic Command Line handling
For newbies looking to get into Windows programming with Visual
C++, the learning curve is steep. Not only do you have to wrestle
with the new object oriented syntax and 'paradigm' of C++, but
the Windows API as encapsulated in MFC as well.
In my case, I found existing literature on the subject to be essentially
useless, with one exception. The excellent Visual C++: Developing Professional Applications in Windows 95 and NT Using MFC by
Marshall Brain and Lance Lovette.
With this example oriented textbook under your belt, you can look
forward to the day when the Visual C++ Tutorial that came
with the compiler will almost make sense. As such, SetTime borrows
shamelessly from the style and content presented within the books
pages.
SetTime is the result of my need to have a useful application
to force me up the learning curve. It's most salient benefit is
that it implements a complete program in one, readable source
code file, namely SetTime.cpp. This program is deliberately
more of a tutorial, rather than yet another Time Synchronizer.
Another goal was to use the Visual C++ Integrated Development
Environment *without* the Appwizard and Classwizard code generators.
This allows me to demonstrate basic concepts without the boatload
of implementation and header files typical of AppWizard projects.
By walking through SetTime and referencing Brain & Lovette's
textbook as well as VC++'s on-line documentation, you will build
an awareness of how a minimal Windows program is built, with enough
features to form an effective underpinning for further study.
Incidentally, you can use it to keep your system clock (or your
wristwatch) in step with the rhythms of the universe, while learning
valuable and marketable skills in a burgeoning area of the computer
industry. It's no exaggeration that programmers who can craft
Internet aware apps will always be in demand.
So stay tuned, and in the meantime, please feel free to forward
questions or comments about the methods employed within SetTime
to pinter@p-squared.com.
SetTime Source Code kit
SetTime is Bearware. That is: free. All I ask is that you drop
a Postcard
in my Guestbook with your Name and the City you are connecting
from, strictly so I can see how far from bear country SetTime
has wandered.
Download the current ZIP File
In closing, I'd like to thank everyone for all the positive Email
and Guestbook comments. I'm gratified that so many people throughout
the world have used SetTime as a basis for further study in VC++,
MFC and WinSock programming. Between us all, we'll figure this
stuff out...
Best regards,
/P2
Revision History:
96/07/25:
- Have frozen the code for SetTime in advance of porting it
to what is clearly the next direction in network oriented programming
languages: Java. My intention is to demonstrate equivalent functionality,
if possible, using Visual J++.
96/07/12:
- Completely overhauled the WinSock subsystem to use Microsoft's
CAsyncSocket class. This has resulted in cleaner, more obvious
coding as well as improved performance. This latest refinement
means that SetTime is specific to VC++ 4.0 or higher, which has
been current for quite some time anyway.
96/05/30:
- Added a key in the System Registry to remember the last Timebase
selected. The key is: HKEY_CURRENT_USER\ Software\P-Squared\SetTime\Options\TimeBase
and defaults to tick.usno.navy.mil the first time SetTime is run.
- Added an Alternate Timebase Selection dialog box for
those users for whom the US Naval Observatory in Washington, DC
is not the nearest timebase.
- Added Basic Command Line Handling. Now, anything on the command
line (ie: /RunOnce) will cause SetTime to attempt to reset
the system clock from the last selected Timebase. Useful if you
are always connected to the Internet and have put SetTime in your
STARTUP folder.
- Added a couple of GDI Graphics Objects to demonstrate
basic functionality. The intention is to eventually adopt a panel
display that resembles Michael Okuda's bridge consoles on Star
Trek:The Next Generation, widely known as Okudagrams.
- Added a Message Box when SetTime discovers the PC is more
than 30 minutes off from the Timebase clock. This helps catch
bogus TZ variables. Safety tip: if a Timebase consistently
reports the wrong time, it's a sign your TZ variable is set wrong.
If you don't need a TZ variable in your AUTOEXEC.BAT, then remove
it, and let Windows (NT or 95) handle Timezones and Daylight Savings
Time settings.
- Still no sign of the final version of Microsoft's ActiveX
controls, and specifically the Internet Control Pack. I'm only
waiting because I want to see C++ examples; only Visual Basic
examples are currently provided. Is it just me, or has anyone
else noticed how adept Microsoft is at producing Betas lately,
rather than finished software?
- Lastly, I've been thinking about putting a line-by-line description
of SetTime together to help explain what is going on and why.
If you are interested in seeing this in a HTML document, send
a note to pinter@p-squared.com
with your vote.