GetCommandLine should return non-const strings.
[wine.git] / programs / clock / main.c
blobcfe8a314e8bce81ecfb12151512b6f031aa25f77
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 CLOCK_GLOBALS Globals;
23 /***********************************************************************
25 * CLOCK_MenuCommand
27 * All handling of main menu events
30 int CLOCK_MenuCommand (WPARAM wParam)
32 switch (wParam) {
33 case CL_ANALOG: {
34 Globals.bAnalog = TRUE;
35 LANGUAGE_UpdateMenuCheckmarks();
36 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
37 break;
39 case CL_DIGITAL: {
40 Globals.bAnalog = FALSE;
41 LANGUAGE_UpdateMenuCheckmarks();
42 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
43 break;
45 case CL_FONT: {
46 MAIN_FileChooseFont();
47 break;
49 case CL_WITHOUT_TITLE: {
50 Globals.bWithoutTitle = !Globals.bWithoutTitle;
51 LANGUAGE_UpdateWindowCaption();
52 LANGUAGE_UpdateMenuCheckmarks();
53 break;
55 case CL_ON_TOP: {
56 Globals.bAlwaysOnTop = !Globals.bAlwaysOnTop;
57 LANGUAGE_UpdateMenuCheckmarks();
58 break;
60 case CL_SECONDS: {
61 Globals.bSeconds = !Globals.bSeconds;
62 LANGUAGE_UpdateMenuCheckmarks();
63 SendMessage(Globals.hMainWnd, WM_PAINT, 0, 0);
64 break;
66 case CL_DATE: {
67 Globals.bDate = !Globals.bDate;
68 LANGUAGE_UpdateMenuCheckmarks();
69 LANGUAGE_UpdateWindowCaption();
70 break;
72 case CL_INFO_LICENSE: {
73 WineLicense(Globals.hMainWnd, Globals.lpszLanguage);
74 break;
76 case CL_INFO_NO_WARRANTY: {
77 WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
78 break;
80 case CL_INFO_ABOUT_WINE: {
81 ShellAbout(Globals.hMainWnd, "Clock", "Clock\n" WINE_RELEASE_INFO, 0);
82 break;
84 /* Handle languages */
85 default:
86 LANGUAGE_DefaultHandle(wParam);
88 return 0;
91 VOID MAIN_FileChooseFont(VOID) {
93 CHOOSEFONT font;
95 font.lStructSize = sizeof(font);
96 font.hwndOwner = Globals.hMainWnd;
97 font.hDC = NULL;
98 font.lpLogFont = 0;
99 font.iPointSize = 0;
100 font.Flags = 0;
101 font.rgbColors = 0;
102 font.lCustData = 0;
103 font.lpfnHook = 0;
104 font.lpTemplateName = 0;
105 font.hInstance = Globals.hInstance;
106 /* font.lpszStyle = LF_FACESIZE; */
107 font.nFontType = 0;
108 font.nSizeMin = 0;
109 font.nSizeMax = 144;
111 if (ChooseFont(&font)) {
112 /* do nothing yet */
117 /***********************************************************************
119 * CLOCK_WndProc
122 LRESULT CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
124 PAINTSTRUCT ps;
125 HDC context;
127 switch (msg) {
129 case WM_CREATE: {
130 printf("WM_CREATE\n");
131 break;
134 case WM_RBUTTONUP: {
135 printf("WM_RBUTTONUP\n");
136 Globals.bWithoutTitle = !Globals.bWithoutTitle;
137 LANGUAGE_UpdateMenuCheckmarks();
138 LANGUAGE_UpdateWindowCaption();
139 UpdateWindow (Globals.hMainWnd);
140 break;
143 case WM_PAINT: {
144 printf("WM_PAINT\n");
145 context = BeginPaint(hWnd, &ps);
146 if(Globals.bAnalog) {
147 DrawFace(context);
148 Idle(context);
150 else
152 /* do nothing */
154 EndPaint(hWnd, &ps);
155 break;
158 case WM_SIZE: {
159 printf("WM_SIZE\n");
160 Globals.MaxX = LOWORD(lParam);
161 Globals.MaxY = HIWORD(lParam);
162 OldHour.DontRedraw = TRUE;
163 OldMinute.DontRedraw = TRUE;
164 OldSecond.DontRedraw = TRUE;
165 break;
168 case WM_COMMAND: {
169 CLOCK_MenuCommand(wParam);
170 break;
173 case WM_DESTROY: {
174 printf("WM_DESTROY\n");
175 PostQuitMessage (0);
176 break;
179 default:
180 return DefWindowProc (hWnd, msg, wParam, lParam);
182 return 0l;
187 /***********************************************************************
189 * WinMain
192 int PASCAL WinMain (HANDLE hInstance, HANDLE prev, LPSTR cmdline, int show)
194 MSG msg;
195 WNDCLASS class;
197 char szClassName[] = "CLClass"; /* To make sure className >= 0x10000 */
198 char szWinName[] = "Clock";
200 /* Setup Globals */
201 Globals.bAnalog = TRUE;
202 Globals.bSeconds = TRUE;
203 Globals.lpszIniFile = "clock.ini";
204 Globals.lpszIcoFile = "clock.ico";
206 /* Select Language */
207 LANGUAGE_Init();
209 Globals.hInstance = hInstance;
210 Globals.hMainIcon = ExtractIcon(Globals.hInstance,
211 Globals.lpszIcoFile, 0);
213 if (!Globals.hMainIcon) Globals.hMainIcon =
214 LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
216 if (!prev){
217 class.style = CS_HREDRAW | CS_VREDRAW;
218 class.lpfnWndProc = CLOCK_WndProc;
219 class.cbClsExtra = 0;
220 class.cbWndExtra = 0;
221 class.hInstance = Globals.hInstance;
222 class.hIcon = LoadIcon (0, IDI_APPLICATION);
223 class.hCursor = LoadCursor (0, IDC_ARROW);
224 class.hbrBackground = GetStockObject (GRAY_BRUSH);
225 class.lpszMenuName = 0;
226 class.lpszClassName = szClassName;
229 if (!RegisterClass (&class)) return FALSE;
231 Globals.hMainWnd = CreateWindow (szClassName, szWinName, WS_OVERLAPPEDWINDOW,
232 CW_USEDEFAULT, 0, CW_USEDEFAULT, Globals.MaxX, Globals.MaxY,
233 LoadMenu(Globals.hInstance, STRING_MENU_Xx), Globals.hInstance, 0);
235 LANGUAGE_SelectByName(Globals.lpszLanguage);
236 SetMenu(Globals.hMainWnd, Globals.hMainMenu);
238 LANGUAGE_UpdateMenuCheckmarks();
240 ShowWindow (Globals.hMainWnd, show);
241 UpdateWindow (Globals.hMainWnd);
243 while (TRUE) {
244 Sleep(1);
245 if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
246 if (msg.message == WM_QUIT) return msg.wParam;
247 TranslateMessage(&msg);
248 DispatchMessage(&msg);
249 Idle(NULL);
251 else Idle(NULL);
254 /* We will never reach the following statement ! */
255 return 0;