5 char* AppName
= "Rolex";
6 char* WindowName
= "Rolex";
8 int WindowHeight
= 121;
9 COLORREF FaceColor
= RGB(192,192,192);
10 COLORREF HandColor
= RGB(0,0,0);
11 COLORREF EtchColor
= RGB(0,0,0);
17 int StartX
,StartY
,EndX
,EndY
;
21 HandData OldSecond
,OldHour
,OldMinute
;
31 SelectObject(dc
,CreateSolidBrush(FaceColor
));
32 SelectObject(dc
,CreatePen(PS_SOLID
,1,EtchColor
));
33 Ellipse(dc
,0,0,MaxX
,MaxY
);
37 MoveToEx(dc
,MidX
+sin(t
*Pi
/6)*0.9*MidX
,MidY
-cos(t
*Pi
/6)*0.9*MidY
,NULL
);
38 LineTo(dc
,MidX
+sin(t
*Pi
/6)*0.8*MidX
,MidY
-cos(t
*Pi
/6)*0.8*MidY
);
40 if(MaxX
>64 && MaxY
>64)
42 SetPixel(dc
,MidX
+sin(t
*Pi
/30)*0.9*MidX
,MidY
-cos(t
*Pi
/30)*0.9*MidY
44 DeleteObject(SelectObject(dc
,GetStockObject(NULL_BRUSH
)));
45 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
46 memset(&OldSecond
,0,sizeof(OldSecond
));
47 memset(&OldMinute
,0,sizeof(OldMinute
));
48 memset(&OldHour
,0,sizeof(OldHour
));
51 void DrawHourHand(HDC dc
)
53 MoveToEx(dc
, OldHour
.StartX
, OldHour
.StartY
, NULL
);
54 LineTo(dc
, OldHour
.EndX
, OldHour
.EndY
);
57 void DrawMinuteHand(HDC dc
)
59 MoveToEx(dc
, OldMinute
.StartX
, OldMinute
.StartY
, NULL
);
60 LineTo(dc
, OldMinute
.EndX
, OldMinute
.EndY
);
63 void DrawSecondHand(HDC dc
)
65 MoveToEx(dc
, OldSecond
.StartX
, OldSecond
.StartY
, NULL
);
66 LineTo(dc
, OldSecond
.EndX
, OldSecond
.EndY
);
69 BOOL
UpdateHourHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
76 Ex
= MidX
+sin(Pos
*Pi
/6000)*XExt
;
77 Ey
= MidY
-cos(Pos
*Pi
/6000)*YExt
;
78 rv
= ( Sx
!=OldHour
.StartX
|| Ex
!=OldHour
.EndX
||
79 Sy
!=OldHour
.StartY
|| Ey
!=OldHour
.EndY
);
80 if(rv
)DrawHourHand(dc
);
81 OldHour
.StartX
= Sx
; OldHour
.EndX
= Ex
;
82 OldHour
.StartY
= Sy
; OldHour
.EndY
= Ey
;
86 BOOL
UpdateMinuteHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
93 Ex
= MidX
+sin(Pos
*Pi
/30000)*XExt
;
94 Ey
= MidY
-cos(Pos
*Pi
/30000)*YExt
;
95 rv
= ( Sx
!=OldMinute
.StartX
|| Ex
!=OldMinute
.EndX
||
96 Sy
!=OldMinute
.StartY
|| Ey
!=OldMinute
.EndY
);
97 if(rv
)DrawMinuteHand(dc
);
98 OldMinute
.StartX
= Sx
; OldMinute
.EndX
= Ex
;
99 OldMinute
.StartY
= Sy
; OldMinute
.EndY
= Ey
;
103 BOOL
UpdateSecondHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
109 Sx
= MidX
; Sy
= MidY
;
110 Ex
= MidX
+sin(Pos
*Pi
/3000)*XExt
;
111 Ey
= MidY
-cos(Pos
*Pi
/3000)*YExt
;
112 rv
= ( Sx
!=OldSecond
.StartX
|| Ex
!=OldSecond
.EndX
||
113 Sy
!=OldSecond
.StartY
|| Ey
!=OldSecond
.EndY
);
114 if(rv
)DrawSecondHand(dc
);
115 OldSecond
.StartX
= Sx
; OldSecond
.EndX
= Ex
;
116 OldSecond
.StartY
= Sy
; OldSecond
.EndY
= Ey
;
138 F
= st
.wMilliseconds
/ 10;
144 SelectObject(dc
,CreatePen(PS_SOLID
,1,FaceColor
));
146 if(UpdateHourHand(dc
,MidX
,MidY
,MidX
*0.5,MidY
*0.5,H
)) Redraw
= TRUE
;
147 if(UpdateMinuteHand(dc
,MidX
,MidY
,MidX
*0.65,MidY
*0.65,M
)) Redraw
= TRUE
;
148 if(UpdateSecondHand(dc
,MidX
,MidY
,MidX
*0.79,MidY
*0.79,F
)) Redraw
= TRUE
;
149 DeleteObject(SelectObject(dc
,CreatePen(PS_SOLID
,1,HandColor
)));
156 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
157 if(!idc
) ReleaseDC(HWindow
,dc
);
160 LRESULT
ProcessAppMsg(HWND wnd
,UINT msg
,WPARAM w
,LPARAM l
)
162 PAINTSTRUCT PaintInfo
;
168 if(GetUpdateRect(wnd
,NULL
,FALSE
))
170 dc
=BeginPaint(wnd
,&PaintInfo
);
173 EndPaint(wnd
,&PaintInfo
);
187 return DefWindowProc (wnd
, msg
, w
, l
);
198 Sleep(1); /* sleep 1 millisecond */
199 if(PeekMessage(&msg
,0,0,0,PM_REMOVE
))
201 if(msg
.message
== WM_QUIT
) return msg
.wParam
;
202 TranslateMessage(&msg
);
203 DispatchMessage(&msg
);
210 int PASCAL
WinMain (HANDLE inst
, HANDLE prev
, LPSTR cmdline
, int show
)
215 class.style
= CS_HREDRAW
| CS_VREDRAW
;
216 class.lpfnWndProc
= ProcessAppMsg
;
217 class.cbClsExtra
= 0;
218 class.cbWndExtra
= 0;
219 class.hInstance
= inst
;
220 class.hIcon
= 0; /* Draw my own icon */
221 class.hCursor
= LoadCursor (0, IDC_ARROW
);
222 class.hbrBackground
= (HBRUSH
)(COLOR_BACKGROUND
+ 1);
223 class.lpszMenuName
= 0;
224 class.lpszClassName
= AppName
;
226 if (!RegisterClass (&class)) return -1;
228 HWindow
=CreateWindowEx(WS_EX_TOPMOST
,AppName
,WindowName
,WS_OVERLAPPEDWINDOW
,
229 CW_USEDEFAULT
,CW_USEDEFAULT
,WindowWidth
,WindowHeight
,
231 memset(&OldSecond
,0,sizeof(OldSecond
));
232 memset(&OldMinute
,0,sizeof(OldMinute
));
233 memset(&OldHour
,0,sizeof(OldHour
));
237 ShowWindow (HWindow
, show
);
238 UpdateWindow (HWindow
);
240 return MessageLoop();