4 * Copyright 1998 Marcel Baur <mbaur@g26.ethz.ch>
6 * Clock is partially based on
7 * - Program Manager by Ulrich Schmied
8 * - rolex.c by Jim Peterson
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #define INITIAL_WINDOW_SIZE 200
40 #define TIMER_PERIOD 50 /* milliseconds */
42 CLOCK_GLOBALS Globals;
44 /***********************************************************************
48 * All handling of main menu events
51 int CLOCK_MenuCommand (WPARAM wParam)
53 CHAR szApp[MAX_STRING_LEN];
54 CHAR szAppRelease[MAX_STRING_LEN];
56 /* switch to analog */
58 Globals.bAnalog = TRUE;
59 LANGUAGE_UpdateMenuCheckmarks();
60 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
63 /* switch to digital */
65 Globals.bAnalog = FALSE;
66 LANGUAGE_UpdateMenuCheckmarks();
67 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
72 MAIN_FileChooseFont();
77 Globals.bWithoutTitle = !Globals.bWithoutTitle;
78 LANGUAGE_UpdateWindowCaption();
79 LANGUAGE_UpdateMenuCheckmarks();
84 Globals.bAlwaysOnTop = !Globals.bAlwaysOnTop;
85 LANGUAGE_UpdateMenuCheckmarks();
88 /* show or hide seconds */
90 Globals.bSeconds = !Globals.bSeconds;
91 LANGUAGE_UpdateMenuCheckmarks();
92 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
95 /* show or hide date */
97 Globals.bDate = !Globals.bDate;
98 LANGUAGE_UpdateMenuCheckmarks();
99 LANGUAGE_UpdateWindowCaption();
104 WineLicense(Globals.hMainWnd);
107 /* show warranties */
109 WineWarranty(Globals.hMainWnd);
112 /* show "about" box */
114 LoadString(Globals.hInstance, 0x10C, szApp, sizeof(szApp));
115 lstrcpy(szAppRelease,szApp);
116 lstrcat(szAppRelease,"\n" PACKAGE_STRING);
117 ShellAbout(Globals.hMainWnd, szApp, szAppRelease, 0);
120 /* Handle languages */
123 LANGUAGE_DefaultHandle(wParam);
129 VOID MAIN_FileChooseFont(VOID)
134 font.lStructSize = sizeof(font);
135 font.hwndOwner = Globals.hMainWnd;
137 font.lpLogFont = &lf;
143 font.lpTemplateName = 0;
144 font.hInstance = Globals.hInstance;
145 /* font.lpszStyle = LF_FACESIZE; */
150 if (ChooseFont(&font)) {
155 /***********************************************************************
160 LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
169 Globals.bWithoutTitle = !Globals.bWithoutTitle;
170 LANGUAGE_UpdateMenuCheckmarks();
171 LANGUAGE_UpdateWindowCaption();
172 UpdateWindow (Globals.hMainWnd);
180 context = BeginPaint(hWnd, &ps);
182 AnalogClock(context, Globals.MaxX, Globals.MaxY);
184 DigitalClock(context, Globals.MaxX, Globals.MaxY);
190 Globals.MaxX = LOWORD(lParam);
191 Globals.MaxY = HIWORD(lParam);
196 CLOCK_MenuCommand(wParam);
201 /* Could just invalidate the changed hands,
202 * but it doesn't really seem worth the effort
204 InvalidateRect(Globals.hMainWnd, NULL, FALSE);
214 return DefWindowProc (hWnd, msg, wParam, lParam);
221 /***********************************************************************
226 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
231 char szClassName[] = "CLClass"; /* To make sure className >= 0x10000 */
232 char szWinName[] = "Clock";
235 Globals.bAnalog = TRUE;
236 Globals.bSeconds = TRUE;
237 Globals.lpszIniFile = "clock.ini";
238 Globals.lpszIcoFile = "clock.ico";
240 Globals.hInstance = hInstance;
241 Globals.hMainIcon = ExtractIcon(Globals.hInstance,
242 Globals.lpszIcoFile, 0);
244 if (!Globals.hMainIcon)
245 Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
248 class.style = CS_HREDRAW | CS_VREDRAW;
249 class.lpfnWndProc = CLOCK_WndProc;
250 class.cbClsExtra = 0;
251 class.cbWndExtra = 0;
252 class.hInstance = Globals.hInstance;
253 class.hIcon = LoadIcon (0, IDI_APPLICATION);
254 class.hCursor = LoadCursor (0, IDC_ARROW);
255 class.hbrBackground = GetStockObject (GRAY_BRUSH);
256 class.lpszMenuName = 0;
257 class.lpszClassName = szClassName;
260 if (!RegisterClass (&class)) return FALSE;
262 Globals.MaxX = Globals.MaxY = INITIAL_WINDOW_SIZE;
263 Globals.hMainWnd = CreateWindow (szClassName, szWinName, WS_OVERLAPPEDWINDOW,
264 CW_USEDEFAULT, CW_USEDEFAULT,
265 Globals.MaxX, Globals.MaxY, 0,
266 0, Globals.hInstance, 0);
268 if (!SetTimer (Globals.hMainWnd, TIMER_ID, TIMER_PERIOD, NULL)) {
269 MessageBox(0, "No available timers", szWinName, MB_ICONEXCLAMATION | MB_OK);
273 LANGUAGE_LoadMenus();
274 SetMenu(Globals.hMainWnd, Globals.hMainMenu);
276 LANGUAGE_UpdateMenuCheckmarks();
278 ShowWindow (Globals.hMainWnd, show);
279 UpdateWindow (Globals.hMainWnd);
281 while (GetMessage(&msg, 0, 0, 0)) {
282 TranslateMessage(&msg);
283 DispatchMessage(&msg);