Release 980601
[wine.git] / programs / clock / main.c
blobd73558bd4fdd2c30ffdbbc076a194796e5c1512d
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_De();
26 void LIBWINE_Register_En();
27 void LIBWINE_Register_Sw();
28 #endif
30 CLOCK_GLOBALS Globals;
32 /***********************************************************************
34 * CLOCK_MenuCommand
36 * All handling of main menu events
39 int CLOCK_MenuCommand (WPARAM wParam)
41 switch (wParam) {
42 case CL_ANALOG: {
43 Globals.bAnalog = TRUE;
44 LANGUAGE_UpdateMenuCheckmarks();
45 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
46 break;
48 case CL_DIGITAL: {
49 Globals.bAnalog = FALSE;
50 LANGUAGE_UpdateMenuCheckmarks();
51 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
52 break;
54 case CL_FONT: {
55 MAIN_FileChooseFont();
56 break;
58 case CL_WITHOUT_TITLE: {
59 Globals.bWithoutTitle = !Globals.bWithoutTitle;
60 LANGUAGE_UpdateWindowCaption();
61 LANGUAGE_UpdateMenuCheckmarks();
62 break;
64 case CL_ON_TOP: {
65 Globals.bAlwaysOnTop = !Globals.bAlwaysOnTop;
66 LANGUAGE_UpdateMenuCheckmarks();
67 break;
69 case CL_SECONDS: {
70 Globals.bSeconds = !Globals.bSeconds;
71 LANGUAGE_UpdateMenuCheckmarks();
72 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
73 break;
75 case CL_DATE: {
76 Globals.bDate = !Globals.bDate;
77 LANGUAGE_UpdateMenuCheckmarks();
78 LANGUAGE_UpdateWindowCaption();
79 break;
81 case CL_INFO_LICENSE: {
82 WineLicense(Globals.hMainWnd, Globals.lpszLanguage);
83 break;
85 case CL_INFO_NO_WARRANTY: {
86 WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
87 break;
89 case CL_INFO_ABOUT_WINE: {
90 ShellAbout(Globals.hMainWnd, "Clock", "Clock\n" WINE_RELEASE_INFO, 0);
91 break;
93 // Handle languages
94 default:
95 LANGUAGE_DefaultHandle(wParam);
97 return 0;
100 VOID MAIN_FileChooseFont(VOID) {
102 CHOOSEFONT font;
104 font.lStructSize = sizeof(font);
105 font.hwndOwner = Globals.hMainWnd;
106 font.hDC = NULL;
107 font.lpLogFont = 0;
108 font.iPointSize = 0;
109 font.Flags = 0;
110 font.rgbColors = 0;
111 font.lCustData = 0;
112 font.lpfnHook = 0;
113 font.lpTemplateName = 0;
114 font.hInstance = Globals.hInstance;
115 font.lpszStyle = LF_FACESIZE;
116 font.nFontType = 0;
117 font.nSizeMin = 0;
118 font.nSizeMax = 0;
120 if (ChooseFont(&font)) {
121 /* do nothing yet */
126 /***********************************************************************
128 * CLOCK_WndProc
131 LRESULT CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
133 PAINTSTRUCT ps;
134 HDC context;
136 switch (msg) {
138 case WM_CREATE: {
139 printf("WM_CREATE\n");
140 break;
143 case WM_RBUTTONUP: {
144 printf("WM_RBUTTONUP\n");
145 Globals.bWithoutTitle = !Globals.bWithoutTitle;
146 LANGUAGE_UpdateMenuCheckmarks();
147 LANGUAGE_UpdateWindowCaption();
148 UpdateWindow (Globals.hMainWnd);
149 break;
152 case WM_PAINT: {
153 printf("WM_PAINT\n");
154 context = BeginPaint(hWnd, &ps);
155 if(Globals.bAnalog) {
156 DrawFace(context);
157 Idle(context);
159 else
161 /* do nothing */
163 EndPaint(hWnd, &ps);
164 break;
167 case WM_SIZE: {
168 printf("WM_SIZE\n");
169 Globals.MaxX = LOWORD(lParam);
170 Globals.MaxY = HIWORD(lParam);
171 OldHour.DontRedraw = TRUE;
172 OldMinute.DontRedraw = TRUE;
173 OldSecond.DontRedraw = TRUE;
174 break;
177 case WM_COMMAND: {
178 CLOCK_MenuCommand(wParam);
179 break;
182 case WM_DESTROY: {
183 printf("WM_DESTROY\n");
184 PostQuitMessage (0);
185 break;
188 default:
189 return DefWindowProc (hWnd, msg, wParam, lParam);
191 return 0l;
196 /***********************************************************************
198 * WinMain
201 int PASCAL WinMain (HANDLE hInstance, HANDLE prev, LPSTR cmdline, int show)
203 MSG msg;
204 WNDCLASS class;
206 char className[] = "CLClass"; /* To make sure className >= 0x10000 */
207 char winName[] = "Clock";
209 #if defined(WINELIB) && !defined(HAVE_WINE_CONSTRUCTOR)
210 /* Register resources */
211 LIBWINE_Register_De();
212 LIBWINE_Register_En();
213 LIBWINE_Register_Sw();
214 #endif
216 printf("WinMain()\n");
218 /* Setup Globals */
219 Globals.bAnalog = TRUE;
220 Globals.bSeconds = TRUE;
221 Globals.lpszIniFile = "clock.ini";
222 Globals.lpszIcoFile = "clock.ico";
224 /* Select Language */
225 LANGUAGE_Init();
227 Globals.hInstance = hInstance;
228 Globals.hMainIcon = ExtractIcon(Globals.hInstance,
229 Globals.lpszIcoFile, 0);
231 if (!Globals.hMainIcon) Globals.hMainIcon =
232 LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
234 if (!prev){
235 class.style = CS_HREDRAW | CS_VREDRAW;
236 class.lpfnWndProc = CLOCK_WndProc;
237 class.cbClsExtra = 0;
238 class.cbWndExtra = 0;
239 class.hInstance = Globals.hInstance;
240 class.hIcon = LoadIcon (0, IDI_APPLICATION);
241 class.hCursor = LoadCursor (0, IDC_ARROW);
242 class.hbrBackground = GetStockObject (GRAY_BRUSH);
243 class.lpszMenuName = 0;
244 class.lpszClassName = className;
247 if (!RegisterClass (&class)) return FALSE;
249 Globals.hMainWnd = CreateWindow (className, winName, WS_OVERLAPPEDWINDOW,
250 CW_USEDEFAULT, 0, CW_USEDEFAULT, Globals.MaxX, Globals.MaxY,
251 LoadMenu(Globals.hInstance, STRING_MENU_Xx),
252 Globals.hInstance, 0);
254 LANGUAGE_SelectByName(Globals.lpszLanguage);
255 SetMenu(Globals.hMainWnd, Globals.hMainMenu);
257 Globals.hSystemMenu = GetSystemMenu(Globals.hMainWnd, TRUE);
259 AppendMenu(Globals.hSystemMenu, MF_STRING | MF_BYCOMMAND, 1000, "item");
260 SetSystemMenu(Globals.hMainWnd, Globals.hSystemMenu);
262 EnableMenuItem(Globals.hPropertiesMenu, CL_FONT, \
263 MF_BYCOMMAND | MF_GRAYED);
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;