Adapted to cursor/icon handling changes.
[wine/multimedia.git] / programs / clock / main.c
blob9ddd49fb8830baacc8d62ac6bc60b04620c07d29
1 /*
2 * Clock
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
12 #include <stdio.h>
13 #include "windows.h"
14 #include "main.h"
15 #include "license.h"
16 #include "version.h"
17 #include "language.h"
18 #include "winclock.h"
19 #include "commdlg.h"
21 #ifdef WINELIB
22 #include "options.h"
23 #include "resource.h"
24 #include "shell.h"
25 void LIBWINE_Register_Da();
26 void LIBWINE_Register_De();
27 void LIBWINE_Register_En();
28 void LIBWINE_Register_Es();
29 void LIBWINE_Register_Fr();
30 void LIBWINE_Register_Sw();
31 void LIBWINE_Register_Fi();
32 #endif
34 CLOCK_GLOBALS Globals;
36 /***********************************************************************
38 * CLOCK_MenuCommand
40 * All handling of main menu events
43 int CLOCK_MenuCommand (WPARAM wParam)
45 switch (wParam) {
46 case CL_ANALOG: {
47 Globals.bAnalog = TRUE;
48 LANGUAGE_UpdateMenuCheckmarks();
49 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
50 break;
52 case CL_DIGITAL: {
53 Globals.bAnalog = FALSE;
54 LANGUAGE_UpdateMenuCheckmarks();
55 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
56 break;
58 case CL_FONT: {
59 MAIN_FileChooseFont();
60 break;
62 case CL_WITHOUT_TITLE: {
63 Globals.bWithoutTitle = !Globals.bWithoutTitle;
64 LANGUAGE_UpdateWindowCaption();
65 LANGUAGE_UpdateMenuCheckmarks();
66 break;
68 case CL_ON_TOP: {
69 Globals.bAlwaysOnTop = !Globals.bAlwaysOnTop;
70 LANGUAGE_UpdateMenuCheckmarks();
71 break;
73 case CL_SECONDS: {
74 Globals.bSeconds = !Globals.bSeconds;
75 LANGUAGE_UpdateMenuCheckmarks();
76 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
77 break;
79 case CL_DATE: {
80 Globals.bDate = !Globals.bDate;
81 LANGUAGE_UpdateMenuCheckmarks();
82 LANGUAGE_UpdateWindowCaption();
83 break;
85 case CL_INFO_LICENSE: {
86 WineLicense(Globals.hMainWnd, Globals.lpszLanguage);
87 break;
89 case CL_INFO_NO_WARRANTY: {
90 WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
91 break;
93 case CL_INFO_ABOUT_WINE: {
94 ShellAbout(Globals.hMainWnd, "Clock", "Clock\n" WINE_RELEASE_INFO, 0);
95 break;
97 /* Handle languages */
98 default:
99 LANGUAGE_DefaultHandle(wParam);
101 return 0;
104 VOID MAIN_FileChooseFont(VOID) {
106 CHOOSEFONT font;
108 font.lStructSize = sizeof(font);
109 font.hwndOwner = Globals.hMainWnd;
110 font.hDC = NULL;
111 font.lpLogFont = 0;
112 font.iPointSize = 0;
113 font.Flags = 0;
114 font.rgbColors = 0;
115 font.lCustData = 0;
116 font.lpfnHook = 0;
117 font.lpTemplateName = 0;
118 font.hInstance = Globals.hInstance;
119 /* font.lpszStyle = LF_FACESIZE; */
120 font.nFontType = 0;
121 font.nSizeMin = 0;
122 font.nSizeMax = 144;
124 if (ChooseFont(&font)) {
125 /* do nothing yet */
130 /***********************************************************************
132 * CLOCK_WndProc
135 LRESULT CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
137 PAINTSTRUCT ps;
138 HDC context;
140 switch (msg) {
142 case WM_CREATE: {
143 printf("WM_CREATE\n");
144 break;
147 case WM_RBUTTONUP: {
148 printf("WM_RBUTTONUP\n");
149 Globals.bWithoutTitle = !Globals.bWithoutTitle;
150 LANGUAGE_UpdateMenuCheckmarks();
151 LANGUAGE_UpdateWindowCaption();
152 UpdateWindow (Globals.hMainWnd);
153 break;
156 case WM_PAINT: {
157 printf("WM_PAINT\n");
158 context = BeginPaint(hWnd, &ps);
159 if(Globals.bAnalog) {
160 DrawFace(context);
161 Idle(context);
163 else
165 /* do nothing */
167 EndPaint(hWnd, &ps);
168 break;
171 case WM_SIZE: {
172 printf("WM_SIZE\n");
173 Globals.MaxX = LOWORD(lParam);
174 Globals.MaxY = HIWORD(lParam);
175 OldHour.DontRedraw = TRUE;
176 OldMinute.DontRedraw = TRUE;
177 OldSecond.DontRedraw = TRUE;
178 break;
181 case WM_COMMAND: {
182 CLOCK_MenuCommand(wParam);
183 break;
186 case WM_DESTROY: {
187 printf("WM_DESTROY\n");
188 PostQuitMessage (0);
189 break;
192 default:
193 return DefWindowProc (hWnd, msg, wParam, lParam);
195 return 0l;
200 /***********************************************************************
202 * WinMain
205 int PASCAL WinMain (HANDLE hInstance, HANDLE prev, LPSTR cmdline, int show)
207 MSG msg;
208 WNDCLASS class;
210 char szClassName[] = "CLClass"; /* To make sure className >= 0x10000 */
211 char szWinName[] = "Clock";
213 #if defined(WINELIB) && !defined(HAVE_WINE_CONSTRUCTOR)
214 /* Register resources */
215 LIBWINE_Register_Da();
216 LIBWINE_Register_De();
217 LIBWINE_Register_En();
218 LIBWINE_Register_Es();
219 LIBWINE_Register_Fr();
220 LIBWINE_Register_Sw();
221 LIBWINE_Register_Fi();
222 #endif
224 /* Setup Globals */
225 Globals.bAnalog = TRUE;
226 Globals.bSeconds = TRUE;
227 Globals.lpszIniFile = "clock.ini";
228 Globals.lpszIcoFile = "clock.ico";
230 /* Select Language */
231 LANGUAGE_Init();
233 Globals.hInstance = hInstance;
234 Globals.hMainIcon = ExtractIcon(Globals.hInstance,
235 Globals.lpszIcoFile, 0);
237 if (!Globals.hMainIcon) Globals.hMainIcon =
238 LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
240 if (!prev){
241 class.style = CS_HREDRAW | CS_VREDRAW;
242 class.lpfnWndProc = CLOCK_WndProc;
243 class.cbClsExtra = 0;
244 class.cbWndExtra = 0;
245 class.hInstance = Globals.hInstance;
246 class.hIcon = LoadIcon (0, IDI_APPLICATION);
247 class.hCursor = LoadCursor (0, IDC_ARROW);
248 class.hbrBackground = GetStockObject (GRAY_BRUSH);
249 class.lpszMenuName = 0;
250 class.lpszClassName = szClassName;
253 if (!RegisterClass (&class)) return FALSE;
255 Globals.hMainWnd = CreateWindow (szClassName, szWinName, WS_OVERLAPPEDWINDOW,
256 CW_USEDEFAULT, 0, CW_USEDEFAULT, Globals.MaxX, Globals.MaxY,
257 LoadMenu(Globals.hInstance, STRING_MENU_Xx), Globals.hInstance, 0);
259 LANGUAGE_SelectByName(Globals.lpszLanguage);
260 SetMenu(Globals.hMainWnd, Globals.hMainMenu);
262 LANGUAGE_UpdateMenuCheckmarks();
264 ShowWindow (Globals.hMainWnd, show);
265 UpdateWindow (Globals.hMainWnd);
267 while (TRUE) {
268 Sleep(1);
269 if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
270 if (msg.message == WM_QUIT) return msg.wParam;
271 TranslateMessage(&msg);
272 DispatchMessage(&msg);
273 Idle(NULL);
275 else Idle(NULL);
278 /* We will never reach the following statement ! */
279 return 0;