Es un reloj digital, es algo simple, pero bueno, quise compartirla con ustedes. Es totalmente personalizable, tanto en tipos de fuentes, tamaños de letra, como colores de fondo, shadow del texto, y color del PEN, asi como el intervalo que actualizará la hora.
Me gustaría poder seleccionar entre un reloj digital y de manecillas, será para una próxima entrega.
Sin más preámbulo aquí esta.
Aquí el Código TEST
Code: Select all
#include <fivewin.ch>
STATIC oWnd, oIcon, oWTimer1, oWTimer2, oWTimer3
STATIC oFontTimer1
STATIC oFontTimer2
STATIC oFontTimer3
FUNCTION main()
LOCAL oIcon1
DEFINE FONT oFontTimer1 NAME "Tahoma" SIZE 16, 16
DEFINE FONT oFontTimer2 NAME "Arial" SIZE 18, 18
DEFINE FONT oFontTimer3 NAME "Times New Roman" SIZE 20, 20
DEFINE ICON oIcon FILE "y:\fwh\icons\fivewin.ICO"
DEFINE WINDOW oWnd TITLE "Test de la Clase Reloj Digital" ICON oIcon
oWTimer1 := TSAYTIMER():new( oWnd, { 10, 30}, oFontTimer1, 1, CLR_BLUE, CLR_WHITE, CLR_RED, CLR_BLUE )
oWTimer2 := TSAYTIMER():new( oWnd, { 70, 30}, oFontTimer2, 2, CLR_WHITE, CLR_BLUE, CLR_BLACK, CLR_HGREEN )
oWTimer3 := TSAYTIMER():new( oWnd, {130, 30}, oFontTimer3, 3, CLR_HGREEN, CLR_RED, CLR_HGRAY, CLR_BLACK )
ACTIVATE WINDOW oWnd
return NIL
Code: Select all
/*
Autor : William Morales
País : México
Correo : wmormar@hotmail.com
Fecha : 25/09/2011 03:28 a.m.
*/
#include <fivewin.ch>
CLASS TSayTimer
DATA oWnd AS OBJECT INIT NIL
DATA oTmr AS OBJECT INIT NIL
DATA oFont AS OBJECT INIT NIL
DATA nClrPen AS NUMERIC INIT CLR_HBLUE
DATA nClrBack AS NUMERIC INIT CLR_BLUE
DATA nClrShadow AS NUMERIC INIT CLR_GRAY
DATA nClrFront AS NUMERIC INIT CLR_WHITE
DATA nInterval AS NUMERIC INIT 1
DATA lFont AS LOGICAL INIT .f.
DATA lFirst AS LOGICAL INIT .t.
DATA cHour AS CHARACTER INIT "0"
DATA cMin AS CHARACTER INIT "0"
DATA cSecs AS CHARACTER INIT "0"
DATA aPos AS ARRAY INIT { 10, 10 }
METHOD new( oWnd, aPos, oFont, nInterval, clrFront, clrShadow, clrBack, clrPen )
METHOD settimer()
METHOD saytimer()
METHOD activate() INLINE ::oTmr:activate()
METHOD pause() INLINE ::oTmr:deactivate()
METHOD END()
ENDCLASS
/**************************************************************************************/
METHOD new( oWnd, aPos, oFont, nInterval, clrFront, clrShadow, clrBack, clrPen )
DEFAULT oWnd := wndmain()
DEFAULT aPos := ::aPos
DEFAULT nInterval := ::nInterval
DEFAULT clrPen := ::nClrPen
DEFAULT clrFront := ::nClrFront
DEFAULT clrShadow := ::nClrShadow
DEFAULT clrBack := ::nClrBack
IF ValType(oFont) == "U"
DEFINE FONT ::oFont NAME "Tahoma" SIZE 18, 18 BOLD
::lFont := .t.
ELSE
::oFont := oFont
ENDIF
::oWnd := oWnd
::aPos := aPos
::nInterval := nInterval * 1000
::nClrPen := clrPen
::nClrFront := clrFront
::nClrShadow := clrShadow
::nClrBack := clrBack
::settimer()
::saytimer()
RETURN Self
/**************************************************************************************/
METHOD settimer()
DEFINE TIMER ::oTmr INTERVAL ::nInterval ACTION ::saytimer() OF ::oWnd
ACTIVATE TIMER ::oTmr
RETURN NIL
/**************************************************************************************/
METHOD saytimer()
LOCAL hDC := 0
LOCAL hPen := 0
LOCAL hBrush := 0
LOCAL nBkOld := 0
LOCAL hFontOld := 0
LOCAL nWidth := 0
LOCAL nHeight := 0
LOCAL cTime := Time()
IF !::oWnd:lVisible
IF ::oTmr:nInterval # 1
::pause()
::oTmr:nInterval := 1
::activate()
ENDIF
RETURN NIL
ELSE
IF ::oTmr:nInterval # ::nInterval
::pause()
::oTmr:nInterval := ::nInterval
::activate()
ENDIF
ENDIF
hDC := ::oWnd:GETDC()
hPen := CreatePen( 1, 3, ::nClrPen )
hBrush := CreateSolidBrush( ::nClrBack )
nBkOld := SetBkMode( hDC, 1 )
hFontOld := SelectObject( hDC, ::oFont:hFont )
nWidth := ::aPos[2] + GetTextWidth( hDC, cTime, ::oFont:hFont )
nHeight := ::aPos[1] + GetTextHeight( ::oFont:hFont, hDC )
Rectangle( hDC, ::aPos[1], ::aPos[2], nHeight + 5, nWidth + 5, hPen )
FillRect( hDC, {::aPos[1] + 2, ::aPos[2] + 2, nHeight + 3, nWidth + 3}, hBrush )
SetTextColor( hDC, ::nClrShadow )
DrawText( hDC, cTime, {::aPos[1] + 3, ::aPos[2] + 3, nHeight, nWidth} )
SetTextColor( hDC, ::nClrFront )
DrawText( hDC, cTime, {::aPos[1] + 4, ::aPos[2] + 4, nHeight, nWidth} )
DeleteObject( hBrush )
DeleteObject( hPen )
SelectObject( hDC, hFontOld )
SetBkMode( hDC, nBkOld )
RETURN NIL
/**************************************************************************************/
METHOD END()
::oTmr:END()
IF ::lFont
::oFont:END()
ENDIF
RETURN NIL
/**************************************************************************************/