home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: InfoMgt
/
InfoMgt.zip
/
ICONCLCK.ZIP
/
CLOCK.C
< prev
next >
Wrap
Text File
|
1990-12-06
|
7KB
|
219 lines
/*-----------------------------
CLOCK.C -- Icon Digital Clock
Developed from programs written by Charles Petzold
-----------------------------*/
#define INCL_WIN
#define INCL_GPI
#define INCL_DOS
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ID_TIMER 1
#define FONTFACE_SYSTEM 0
#define FONTFACE_COUR 1
#define FONTFACE_HELV 2
#define FONTFACE_TIMES 3
#define FONTSIZE_8 0
#define FONTSIZE_10 1
#define FONTSIZE_12 2
#define FONTSIZE_14 3
#define FONTSIZE_18 4
#define FONTSIZE_24 5
static SHORT sFontSize[6] = { 80, 100, 120, 140, 180, 240 };
static CHAR *szFacename[4] = { "System Proportional",
"Courier", "Helv", "Tms Rmn" };
static LONG alMatch[4][6];
MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM);
VOID SizeTheWindow (HWND);
BOOL EzfQueryFonts (HPS hps);
LONG EzfCreateLogFont (HPS hps, LONG lcid, USHORT idFace, USHORT idSize,
USHORT fsSelection);
int main (void)
{
static CHAR szClientClass[] = "Clock";
static ULONG flFrameFlags = FCF_SYSMENU | FCF_TITLEBAR;
static ULONG flFrameStyle = WS_VISIBLE | WS_MINIMIZED;
HAB hab;
HMQ hmq;
HWND hwndFrame, hwndClient;
QMSG qmsg;
hab = WinInitialize (0);
hmq = WinCreateMsgQueue (hab, 0);
WinRegisterClass (hab, szClientClass, ClientWndProc, 0L, 0);
hwndFrame = WinCreateStdWindow (HWND_DESKTOP, flFrameStyle,
&flFrameFlags, szClientClass, NULL,
0L, NULL, 0, &hwndClient);
WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, 0, 0,
SWP_MINIMIZE | SWP_SHOW);
if (WinStartTimer (hab, hwndClient, ID_TIMER, 10000))
{ while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
WinDispatchMsg (hab, &qmsg);
WinStopTimer (hab, hwndClient, ID_TIMER);
}
else
WinMessageBox (HWND_DESKTOP, hwndClient, "Too many clocks or timers",
szClientClass, 0, MB_OK | MB_ICONEXCLAMATION);
WinDestroyWindow (hwndFrame);
WinDestroyMsgQueue (hmq);
WinTerminate (hab);
return 0;
}
VOID UpdateTime (HWND hwnd, HPS hps)
{
static BOOL fHaveCtryInfo = FALSE;
static COUNTRYCODE ctryc = { 0, 0 };
static COUNTRYINFO ctryi;
CHAR szBuffer [20];
DATETIME dt;
RECTL rcl;
USHORT usDataLength;
/*----------------------------------------
Get Country Information, Date and Time
----------------------------------------*/
if (!fHaveCtryInfo)
{ DosGetCtryInfo (sizeof ctryi, &ctryc, &ctryi, &usDataLength) ;
fHaveCtryInfo = TRUE ;
}
DosGetDateTime (&dt) ;
/*-------------
Format Time
-------------*/
/*----------------
12-hour format
----------------*/
if ((ctryi.fsTimeFmt & 1) == 0)
sprintf (szBuffer, "%d%s%02d", (dt.hours + 11) % 12 + 1,
ctryi.szTimeSeparator, dt.minutes);
/*----------------
24-hour format
----------------*/
else
sprintf (szBuffer, " %02d%s%02d ", dt.hours, ctryi.szTimeSeparator,
dt.minutes);
/*--------------
Display Time
--------------*/
EzfCreateLogFont(hps, 1L, FONTFACE_TIMES, FONTSIZE_10, FATTR_SEL_BOLD);
GpiSetCharSet(hps, 1L);
WinQueryWindowRect (hwnd, &rcl) ;
WinDrawText (hps, -1, szBuffer, &rcl, CLR_NEUTRAL, CLR_BACKGROUND,
DT_CENTER | DT_VCENTER) ;
}
MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
HPS hps;
FONTMETRICS fm ;
switch (msg)
{ case WM_CREATE : hps = WinGetPS (hwnd);
EzfQueryFonts(hps);
EzfCreateLogFont(hps, 1L, FONTFACE_TIMES, FONTSIZE_10, FATTR_SEL_BOLD);
GpiSetCharSet(hps, 1L);
GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm);
WinReleasePS (hps);
case WM_TIMER : hps = WinGetPS (hwnd);
// GpiSetBackMix (hps, BM_OVERPAINT);
GpiErase (hps);
UpdateTime (hwnd, hps);
WinReleasePS (hps);
return 0;
case WM_PAINT : hps = WinBeginPaint (hwnd, NULL, NULL);
GpiErase (hps);
UpdateTime (hwnd, hps);
WinEndPaint (hps);
return 0;
}
return WinDefWindowProc (hwnd, msg, mp1, mp2);
}
BOOL EzfQueryFonts (HPS hps)
{
FONTMETRICS *pfm;
HDC hdc;
LONG lHorzRes, lVertRes, lRequestFonts, lNumberFonts;
SHORT sIndex, sFace, sSize;
hdc = GpiQueryDevice (hps);
DevQueryCaps (hdc, CAPS_HORIZONTAL_FONT_RES, 1L, &lHorzRes);
DevQueryCaps (hdc, CAPS_VERTICAL_FONT_RES, 1L, &lVertRes);
for (sFace = 0 ; sFace < 4 ; sFace++)
{ lRequestFonts = 0;
lNumberFonts = GpiQueryFonts (hps, QF_PUBLIC, szFacename[sFace],
&lRequestFonts, 0L, NULL);
if (lNumberFonts == 0)
continue;
if (lNumberFonts * sizeof (FONTMETRICS) >= 65536L)
return FALSE;
pfm = malloc ((SHORT) lNumberFonts * sizeof (FONTMETRICS));
if (pfm == NULL)
return FALSE;
GpiQueryFonts (hps, QF_PUBLIC, szFacename[sFace],
&lNumberFonts, (LONG) sizeof (FONTMETRICS), pfm);
for (sIndex = 0 ; sIndex < (SHORT) lNumberFonts ; sIndex++)
if (pfm[sIndex].sXDeviceRes == (SHORT) lHorzRes &&
pfm[sIndex].sYDeviceRes == (SHORT) lVertRes &&
(pfm[sIndex].fsDefn & 1) == 0)
{ for (sSize = 0 ; sSize < 6 ; sSize++)
if (pfm[sIndex].sNominalPointSize == sFontSize[sSize])
break;
if (sSize != 6)
alMatch[sFace][sSize] = pfm[sIndex].lMatch;
}
free (pfm);
}
return TRUE;
}
LONG EzfCreateLogFont (HPS hps, LONG lcid, USHORT idFace, USHORT idSize,
USHORT fsSelection)
{
static FATTRS fat;
if (idFace > 3 || idSize > 5 || alMatch[idFace][idSize] == 0)
return FALSE;
fat.usRecordLength = sizeof fat;
fat.fsSelection = fsSelection;
fat.lMatch = alMatch[idFace][idSize];
strcpy (fat.szFacename, szFacename[idFace]);
return GpiCreateLogFont (hps, NULL, lcid, &fat);
}