1 /*********************************************************************
3 * rolex.c: Windows clock application for WINE (by Jim Peterson) *
5 * This is a translation of a Turbo Pascal OWL application I made *
6 * once, so it's a little flaky (tons of globals, functions that *
7 * could have been in-lined, etc.). The source code should easily *
8 * compile with a standard Win32 C compiler. *
10 * To try it out, type 'make rolex'. *
12 *********************************************************************/
18 char* AppName
= "Rolex";
19 char* WindowName
= "Rolex";
20 int WindowWidth
= 100;
21 int WindowHeight
= 121;
22 COLORREF FaceColor
= RGB(192,192,192);
23 COLORREF HandColor
= RGB(0,0,0);
24 COLORREF EtchColor
= RGB(0,0,0);
30 int StartX
,StartY
,EndX
,EndY
;
34 HandData OldSecond
,OldHour
,OldMinute
;
44 SelectObject(dc
,CreateSolidBrush(FaceColor
));
45 SelectObject(dc
,CreatePen(PS_SOLID
,1,EtchColor
));
46 Ellipse(dc
,0,0,MaxX
,MaxY
);
50 MoveToEx(dc
,MidX
+sin(t
*Pi
/6)*0.9*MidX
,MidY
-cos(t
*Pi
/6)*0.9*MidY
,NULL
);
51 LineTo(dc
,MidX
+sin(t
*Pi
/6)*0.8*MidX
,MidY
-cos(t
*Pi
/6)*0.8*MidY
);
53 if(MaxX
>64 && MaxY
>64)
55 SetPixel(dc
,MidX
+sin(t
*Pi
/30)*0.9*MidX
,MidY
-cos(t
*Pi
/30)*0.9*MidY
57 DeleteObject(SelectObject(dc
,GetStockObject(NULL_BRUSH
)));
58 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
59 memset(&OldSecond
,0,sizeof(OldSecond
));
60 memset(&OldMinute
,0,sizeof(OldMinute
));
61 memset(&OldHour
,0,sizeof(OldHour
));
64 void DrawHourHand(HDC dc
)
66 MoveToEx(dc
, OldHour
.StartX
, OldHour
.StartY
, NULL
);
67 LineTo(dc
, OldHour
.EndX
, OldHour
.EndY
);
70 void DrawMinuteHand(HDC dc
)
72 MoveToEx(dc
, OldMinute
.StartX
, OldMinute
.StartY
, NULL
);
73 LineTo(dc
, OldMinute
.EndX
, OldMinute
.EndY
);
76 void DrawSecondHand(HDC dc
)
78 MoveToEx(dc
, OldSecond
.StartX
, OldSecond
.StartY
, NULL
);
79 LineTo(dc
, OldSecond
.EndX
, OldSecond
.EndY
);
82 BOOL
UpdateHourHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
89 Ex
= MidX
+sin(Pos
*Pi
/6000)*XExt
;
90 Ey
= MidY
-cos(Pos
*Pi
/6000)*YExt
;
91 rv
= ( Sx
!=OldHour
.StartX
|| Ex
!=OldHour
.EndX
||
92 Sy
!=OldHour
.StartY
|| Ey
!=OldHour
.EndY
);
93 if(rv
)DrawHourHand(dc
);
94 OldHour
.StartX
= Sx
; OldHour
.EndX
= Ex
;
95 OldHour
.StartY
= Sy
; OldHour
.EndY
= Ey
;
99 BOOL
UpdateMinuteHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
105 Sx
= MidX
; Sy
= MidY
;
106 Ex
= MidX
+sin(Pos
*Pi
/30000)*XExt
;
107 Ey
= MidY
-cos(Pos
*Pi
/30000)*YExt
;
108 rv
= ( Sx
!=OldMinute
.StartX
|| Ex
!=OldMinute
.EndX
||
109 Sy
!=OldMinute
.StartY
|| Ey
!=OldMinute
.EndY
);
110 if(rv
)DrawMinuteHand(dc
);
111 OldMinute
.StartX
= Sx
; OldMinute
.EndX
= Ex
;
112 OldMinute
.StartY
= Sy
; OldMinute
.EndY
= Ey
;
116 BOOL
UpdateSecondHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
122 Sx
= MidX
; Sy
= MidY
;
123 Ex
= MidX
+sin(Pos
*Pi
/3000)*XExt
;
124 Ey
= MidY
-cos(Pos
*Pi
/3000)*YExt
;
125 rv
= ( Sx
!=OldSecond
.StartX
|| Ex
!=OldSecond
.EndX
||
126 Sy
!=OldSecond
.StartY
|| Ey
!=OldSecond
.EndY
);
127 if(rv
)DrawSecondHand(dc
);
128 OldSecond
.StartX
= Sx
; OldSecond
.EndX
= Ex
;
129 OldSecond
.StartY
= Sy
; OldSecond
.EndY
= Ey
;
151 F
= st
.wMilliseconds
/ 10;
157 SelectObject(dc
,CreatePen(PS_SOLID
,1,FaceColor
));
159 if(UpdateHourHand(dc
,MidX
,MidY
,MidX
*0.5,MidY
*0.5,H
)) Redraw
= TRUE
;
160 if(UpdateMinuteHand(dc
,MidX
,MidY
,MidX
*0.65,MidY
*0.65,M
)) Redraw
= TRUE
;
161 if(UpdateSecondHand(dc
,MidX
,MidY
,MidX
*0.79,MidY
*0.79,F
)) Redraw
= TRUE
;
162 DeleteObject(SelectObject(dc
,CreatePen(PS_SOLID
,1,HandColor
)));
169 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
170 if(!idc
) ReleaseDC(HWindow
,dc
);
173 LRESULT
ProcessAppMsg(HWND wnd
,UINT msg
,WPARAM w
,LPARAM l
)
175 PAINTSTRUCT PaintInfo
;
181 if(GetUpdateRect(wnd
,NULL
,FALSE
))
183 dc
=BeginPaint(wnd
,&PaintInfo
);
186 EndPaint(wnd
,&PaintInfo
);
200 return DefWindowProc (wnd
, msg
, w
, l
);
211 Sleep(1); /* sleep 1 millisecond */
212 if(PeekMessage(&msg
,0,0,0,PM_REMOVE
))
214 if(msg
.message
== WM_QUIT
) return msg
.wParam
;
215 TranslateMessage(&msg
);
216 DispatchMessage(&msg
);
223 int PASCAL
WinMain (HANDLE inst
, HANDLE prev
, LPSTR cmdline
, int show
)
228 class.style
= CS_HREDRAW
| CS_VREDRAW
;
229 class.lpfnWndProc
= ProcessAppMsg
;
230 class.cbClsExtra
= 0;
231 class.cbWndExtra
= 0;
232 class.hInstance
= inst
;
233 class.hIcon
= 0; /* Draw my own icon */
234 class.hCursor
= LoadCursor (0, IDC_ARROW
);
235 class.hbrBackground
= (HBRUSH
)(COLOR_BACKGROUND
+ 1);
236 class.lpszMenuName
= 0;
237 class.lpszClassName
= AppName
;
239 if (!RegisterClass (&class)) return -1;
241 HWindow
=CreateWindowEx(WS_EX_TOPMOST
,AppName
,WindowName
,WS_OVERLAPPEDWINDOW
,
242 CW_USEDEFAULT
,CW_USEDEFAULT
,WindowWidth
,WindowHeight
,
244 memset(&OldSecond
,0,sizeof(OldSecond
));
245 memset(&OldMinute
,0,sizeof(OldMinute
));
246 memset(&OldHour
,0,sizeof(OldHour
));
250 ShowWindow (HWindow
, show
);
251 UpdateWindow (HWindow
);
253 return MessageLoop();