- Use 'MS Shell Dlg' font in all dialogs.
[reactos.git] / reactos / lib / syssetup / wizard.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: wizard.c,v 1.5 2004/08/03 13:43:00 ekohl Exp $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS system libraries
23 * PURPOSE: System setup
24 * FILE: lib/syssetup/wizard.c
25 * PROGRAMER: Eric Kohl
26 */
27
28 /* INCLUDES *****************************************************************/
29
30 #include <windows.h>
31 #include <commctrl.h>
32
33 #include <string.h>
34 #include <tchar.h>
35
36 #include <syssetup.h>
37
38 #include "globals.h"
39 #include "resource.h"
40
41
42 /* GLOBALS ******************************************************************/
43
44 static SETUPDATA SetupData;
45
46
47 /* FUNCTIONS ****************************************************************/
48
49 static VOID
50 CenterWindow(HWND hWnd)
51 {
52 HWND hWndParent;
53 RECT rcParent;
54 RECT rcWindow;
55
56 hWndParent = GetParent(hWnd);
57 if (hWndParent == NULL)
58 hWndParent = GetDesktopWindow();
59
60 GetWindowRect(hWndParent, &rcParent);
61 GetWindowRect(hWnd, &rcWindow);
62
63 SetWindowPos(hWnd,
64 HWND_TOP,
65 ((rcParent.right - rcParent.left) - (rcWindow.right - rcWindow.left)) / 2,
66 ((rcParent.bottom - rcParent.top) - (rcWindow.bottom - rcWindow.top)) / 2,
67 0,
68 0,
69 SWP_NOSIZE);
70 }
71
72
73 BOOL CALLBACK
74 WelcomeDlgProc(HWND hwndDlg,
75 UINT uMsg,
76 WPARAM wParam,
77 LPARAM lParam)
78 {
79 switch (uMsg)
80 {
81 case WM_INITDIALOG:
82 {
83 HWND hwndControl;
84 DWORD dwStyle;
85
86 hwndControl = GetParent(hwndDlg);
87
88 /* Center the wizard window */
89 CenterWindow (hwndControl);
90
91 /* Hide the system menu */
92 dwStyle = GetWindowLong(hwndControl, GWL_STYLE);
93 SetWindowLong(hwndControl, GWL_STYLE, dwStyle & ~WS_SYSMENU);
94
95 /* Hide and disable the 'Cancel' button */
96 hwndControl = GetDlgItem(GetParent(hwndDlg), IDCANCEL);
97 ShowWindow (hwndControl, SW_HIDE);
98 EnableWindow (hwndControl, FALSE);
99 }
100 break;
101
102
103 case WM_NOTIFY:
104 {
105 LPNMHDR lpnm = (LPNMHDR)lParam;
106
107 switch (lpnm->code)
108 {
109 case PSN_SETACTIVE:
110 /* Enable the Next button */
111 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
112 break;
113
114 default:
115 break;
116 }
117 }
118 break;
119
120 default:
121 break;
122 }
123
124 return FALSE;
125 }
126
127
128 BOOL CALLBACK
129 OwnerPageDlgProc(HWND hwndDlg,
130 UINT uMsg,
131 WPARAM wParam,
132 LPARAM lParam)
133 {
134 TCHAR OwnerName[51];
135 TCHAR OwnerOrganization[51];
136 HKEY hKey;
137 LPNMHDR lpnm;
138
139 switch (uMsg)
140 {
141 case WM_INITDIALOG:
142 {
143 SendDlgItemMessage(hwndDlg, IDC_OWNERNAME, EM_LIMITTEXT, 50, 0);
144 SendDlgItemMessage(hwndDlg, IDC_OWNERORGANIZATION, EM_LIMITTEXT, 50, 0);
145
146 /* Set focus to owner name */
147 SetFocus(GetDlgItem(hwndDlg, IDC_OWNERNAME));
148 }
149 break;
150
151
152 case WM_NOTIFY:
153 {
154 lpnm = (LPNMHDR)lParam;
155
156 switch (lpnm->code)
157 {
158 case PSN_SETACTIVE:
159 /* Enable the Back and Next buttons */
160 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
161 break;
162
163 case PSN_WIZNEXT:
164 OwnerName[0] = 0;
165 if (GetDlgItemText(hwndDlg, IDC_OWNERNAME, OwnerName, 50) == 0)
166 {
167 MessageBox(hwndDlg,
168 _T("Setup cannot continue until you enter your name."),
169 _T("ReactOS Setup"),
170 MB_ICONERROR | MB_OK);
171 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
172 return TRUE;
173 }
174
175 OwnerOrganization[0] = 0;
176 GetDlgItemText(hwndDlg, IDC_OWNERORGANIZATION, OwnerOrganization, 50);
177
178 RegOpenKeyEx(HKEY_LOCAL_MACHINE,
179 _T("Software\\Microsoft\\Windows NT\\CurrentVersion"),
180 0,
181 KEY_ALL_ACCESS,
182 &hKey);
183 /* FIXME: check error code */
184
185 RegSetValueEx(hKey,
186 _T("RegisteredOwner"),
187 0,
188 REG_SZ,
189 OwnerName,
190 (_tcslen(OwnerName) + 1) * sizeof(TCHAR));
191 /* FIXME: check error code */
192
193 RegSetValueEx(hKey,
194 _T("RegisteredOrganization"),
195 0,
196 REG_SZ,
197 OwnerOrganization,
198 (_tcslen(OwnerOrganization) + 1) * sizeof(TCHAR));
199 /* FIXME: check error code */
200
201 RegCloseKey(hKey);
202 break;
203
204 default:
205 break;
206 }
207 }
208 break;
209
210 default:
211 break;
212 }
213
214 return FALSE;
215 }
216
217
218 BOOL CALLBACK
219 ComputerPageDlgProc(HWND hwndDlg,
220 UINT uMsg,
221 WPARAM wParam,
222 LPARAM lParam)
223 {
224 TCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
225 TCHAR Password1[15];
226 TCHAR Password2[15];
227 DWORD Length;
228 LPNMHDR lpnm;
229
230 switch (uMsg)
231 {
232 case WM_INITDIALOG:
233 {
234 /* Retrieve current computer name */
235 Length = MAX_COMPUTERNAME_LENGTH + 1;
236 GetComputerName(ComputerName, &Length);
237
238 /* Display current computer name */
239 SetDlgItemText(hwndDlg, IDC_COMPUTERNAME, ComputerName);
240
241 /* Set text limits */
242 SendDlgItemMessage(hwndDlg, IDC_COMPUTERNAME, EM_LIMITTEXT, 64, 0);
243 SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD1, EM_LIMITTEXT, 14, 0);
244 SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD2, EM_LIMITTEXT, 14, 0);
245
246 /* Set focus to computer name */
247 SetFocus(GetDlgItem(hwndDlg, IDC_COMPUTERNAME));
248 }
249 break;
250
251
252 case WM_NOTIFY:
253 {
254 lpnm = (LPNMHDR)lParam;
255
256 switch (lpnm->code)
257 {
258 case PSN_SETACTIVE:
259 /* Enable the Back and Next buttons */
260 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
261 break;
262
263 case PSN_WIZNEXT:
264 if (GetDlgItemText(hwndDlg, IDC_COMPUTERNAME, ComputerName, 64) == 0)
265 {
266 MessageBox(hwndDlg,
267 _T("Setup cannot continue until you enter the name of your computer."),
268 _T("ReactOS Setup"),
269 MB_ICONERROR | MB_OK);
270 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
271 return TRUE;
272 }
273
274 /* FIXME: check computer name for invalid characters */
275
276 if (!SetComputerName(ComputerName))
277 {
278 MessageBox(hwndDlg,
279 _T("Setup failed to set the computer name."),
280 _T("ReactOS Setup"),
281 MB_ICONERROR | MB_OK);
282 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
283 return TRUE;
284 }
285
286 /* Check admin passwords */
287 GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD1, Password1, 15);
288 GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD2, Password2, 15);
289 if (_tcscmp(Password1, Password2))
290 {
291 MessageBox(hwndDlg,
292 _T("The passwords you entered do not match. Please enter "\
293 "the desired password again."),
294 _T("ReactOS Setup"),
295 MB_ICONERROR | MB_OK);
296 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
297 return TRUE;
298 }
299
300 /* FIXME: check password for invalid characters */
301
302 /* FIXME: Set admin password */
303 break;
304
305 default:
306 break;
307 }
308 }
309 break;
310
311 default:
312 break;
313 }
314
315 return FALSE;
316 }
317
318
319 BOOL CALLBACK
320 LocalePageDlgProc(HWND hwndDlg,
321 UINT uMsg,
322 WPARAM wParam,
323 LPARAM lParam)
324 {
325 PSETUPDATA SetupData;
326
327 /* Retrieve pointer to the global setup data */
328 SetupData = (PSETUPDATA)GetWindowLong (hwndDlg, GWL_USERDATA);
329
330 switch (uMsg)
331 {
332 case WM_INITDIALOG:
333 {
334 /* Save pointer to the global setup data */
335 SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
336 SetWindowLong(hwndDlg, GWL_USERDATA, (LONG)SetupData);
337
338 }
339 break;
340
341
342 case WM_NOTIFY:
343 {
344 LPNMHDR lpnm = (LPNMHDR)lParam;
345
346 switch (lpnm->code)
347 {
348 case PSN_SETACTIVE:
349 /* Enable the Back and Next buttons */
350 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
351 break;
352
353 case PSN_WIZNEXT:
354 break;
355
356 default:
357 break;
358 }
359 }
360 break;
361
362 default:
363 break;
364 }
365
366 return FALSE;
367 }
368
369
370 BOOL CALLBACK
371 FinishDlgProc(HWND hwndDlg,
372 UINT uMsg,
373 WPARAM wParam,
374 LPARAM lParam)
375 {
376
377 switch (uMsg)
378 {
379 case WM_INITDIALOG:
380 break;
381
382 case WM_NOTIFY:
383 {
384 LPNMHDR lpnm = (LPNMHDR)lParam;
385
386 switch (lpnm->code)
387 {
388 case PSN_SETACTIVE:
389 /* Enable the correct buttons on for the active page */
390 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);
391 break;
392
393 case PSN_WIZBACK:
394 /* Handle a Back button click, if necessary */
395 break;
396
397 case PSN_WIZFINISH:
398 /* Handle a Finish button click, if necessary */
399 break;
400
401 default:
402 break;
403 }
404 }
405 break;
406
407 default:
408 break;
409 }
410
411 return FALSE;
412 }
413
414
415 VOID
416 InstallWizard(VOID)
417 {
418 PROPSHEETHEADER psh;
419 HPROPSHEETPAGE ahpsp[5];
420 PROPSHEETPAGE psp;
421 // SHAREDWIZDATA wizdata;
422
423 /* Clear setup data */
424 ZeroMemory(&SetupData, sizeof(SETUPDATA));
425
426 /* Create the Welcome page */
427 ZeroMemory (&psp, sizeof(PROPSHEETPAGE));
428 psp.dwSize = sizeof(PROPSHEETPAGE);
429 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
430 psp.hInstance = hDllInstance;
431 psp.lParam = (LPARAM)&SetupData;
432 psp.pfnDlgProc = WelcomeDlgProc;
433 psp.pszTemplate = MAKEINTRESOURCE(IDD_WELCOMEPAGE);
434 ahpsp[0] = CreatePropertySheetPage(&psp);
435
436 /* Create the Owner page */
437 psp.dwFlags = PSP_DEFAULT; // | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
438 // psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TITLE1);
439 // psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_SUBTITLE1);
440 psp.pszTemplate = MAKEINTRESOURCE(IDD_OWNERPAGE);
441 psp.pfnDlgProc = OwnerPageDlgProc;
442 ahpsp[1] = CreatePropertySheetPage(&psp);
443
444 /* Create the Computer page */
445 psp.dwFlags = PSP_DEFAULT; // | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
446 // psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TITLE2);
447 // psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_SUBTITLE2);
448 psp.pfnDlgProc = ComputerPageDlgProc;
449 psp.pszTemplate = MAKEINTRESOURCE(IDD_COMPUTERPAGE);
450 ahpsp[2] = CreatePropertySheetPage(&psp);
451
452
453 /* Create the Locale page */
454 psp.dwFlags = PSP_DEFAULT; // | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
455 // psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TITLE2);
456 // psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_SUBTITLE2);
457 psp.pfnDlgProc = LocalePageDlgProc;
458 psp.pszTemplate = MAKEINTRESOURCE(IDD_LOCALEPAGE);
459 ahpsp[3] = CreatePropertySheetPage(&psp);
460
461
462 /* Create the Finish page */
463 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
464 psp.pfnDlgProc = FinishDlgProc;
465 psp.pszTemplate = MAKEINTRESOURCE(IDD_FINISHPAGE);
466 ahpsp[4] = CreatePropertySheetPage(&psp);
467
468 /* Create the property sheet */
469 psh.dwSize = sizeof(PROPSHEETHEADER);
470 psh.dwFlags = PSH_WIZARD; //97 | PSH_WATERMARK | PSH_HEADER;
471 psh.hInstance = hDllInstance;
472 psh.hwndParent = NULL;
473 psh.nPages = 5;
474 psh.nStartPage = 0;
475 psh.phpage = ahpsp;
476 // psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
477 // psh.pszbmHeader = MAKEINTRESOURCE(IDB_HEADER);
478
479 /* Display the wizard */
480 PropertySheet(&psh);
481 }
482
483 /* EOF */