3 * Copyright (C) 2004 ReactOS Team
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.
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.
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.
19 /* $Id: wizard.c,v 1.10 2004/11/02 15:42:09 ekohl Exp $
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
28 /* INCLUDES *****************************************************************/
44 /* GLOBALS ******************************************************************/
46 static SETUPDATA SetupData
;
49 /* FUNCTIONS ****************************************************************/
52 CenterWindow(HWND hWnd
)
58 hWndParent
= GetParent(hWnd
);
59 if (hWndParent
== NULL
)
60 hWndParent
= GetDesktopWindow();
62 GetWindowRect(hWndParent
, &rcParent
);
63 GetWindowRect(hWnd
, &rcWindow
);
67 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
68 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
84 ncm
.cbSize
= sizeof(NONCLIENTMETRICS
);
85 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
87 LogFont
= ncm
.lfMessageFont
;
88 LogFont
.lfWeight
= FW_BOLD
;
89 _tcscpy(LogFont
.lfFaceName
, TEXT("MS Shell Dlg"));
93 LogFont
.lfHeight
= 0 - GetDeviceCaps (hdc
, LOGPIXELSY
) * FontSize
/ 72;
94 hFont
= CreateFontIndirect(&LogFont
);
102 WelcomeDlgProc(HWND hwndDlg
,
111 PSETUPDATA SetupData
;
115 /* Get pointer to the global setup data */
116 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
118 hwndControl
= GetParent(hwndDlg
);
120 /* Center the wizard window */
121 CenterWindow (hwndControl
);
123 /* Hide the system menu */
124 dwStyle
= GetWindowLong(hwndControl
, GWL_STYLE
);
125 SetWindowLong(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
127 /* Hide and disable the 'Cancel' button */
128 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
129 ShowWindow (hwndControl
, SW_HIDE
);
130 EnableWindow (hwndControl
, FALSE
);
133 SendDlgItemMessage(hwndDlg
,
136 (WPARAM
)SetupData
->hTitleFont
,
144 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
149 /* Enable the Next button */
150 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
168 OwnerPageDlgProc(HWND hwndDlg
,
174 TCHAR OwnerOrganization
[51];
182 SendDlgItemMessage(hwndDlg
, IDC_OWNERNAME
, EM_LIMITTEXT
, 50, 0);
183 SendDlgItemMessage(hwndDlg
, IDC_OWNERORGANIZATION
, EM_LIMITTEXT
, 50, 0);
185 /* Set focus to owner name */
186 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
193 lpnm
= (LPNMHDR
)lParam
;
198 /* Enable the Back and Next buttons */
199 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
204 if (GetDlgItemText(hwndDlg
, IDC_OWNERNAME
, OwnerName
, 50) == 0)
207 _T("Setup cannot continue until you enter your name."),
209 MB_ICONERROR
| MB_OK
);
210 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, -1);
214 OwnerOrganization
[0] = 0;
215 GetDlgItemText(hwndDlg
, IDC_OWNERORGANIZATION
, OwnerOrganization
, 50);
217 RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
218 _T("Software\\Microsoft\\Windows NT\\CurrentVersion"),
222 /* FIXME: check error code */
225 _T("RegisteredOwner"),
229 (_tcslen(OwnerName
) + 1) * sizeof(TCHAR
));
230 /* FIXME: check error code */
233 _T("RegisteredOrganization"),
237 (_tcslen(OwnerOrganization
) + 1) * sizeof(TCHAR
));
238 /* FIXME: check error code */
258 ComputerPageDlgProc(HWND hwndDlg
,
263 TCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
273 /* Retrieve current computer name */
274 Length
= MAX_COMPUTERNAME_LENGTH
+ 1;
275 GetComputerName(ComputerName
, &Length
);
277 /* Display current computer name */
278 SetDlgItemText(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
);
280 /* Set text limits */
281 SendDlgItemMessage(hwndDlg
, IDC_COMPUTERNAME
, EM_LIMITTEXT
, 64, 0);
282 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD1
, EM_LIMITTEXT
, 14, 0);
283 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD2
, EM_LIMITTEXT
, 14, 0);
285 /* Set focus to computer name */
286 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
293 lpnm
= (LPNMHDR
)lParam
;
298 /* Enable the Back and Next buttons */
299 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
303 if (GetDlgItemText(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
, 64) == 0)
306 _T("Setup cannot continue until you enter the name of your computer."),
308 MB_ICONERROR
| MB_OK
);
309 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, -1);
313 /* FIXME: check computer name for invalid characters */
315 if (!SetComputerName(ComputerName
))
318 _T("Setup failed to set the computer name."),
320 MB_ICONERROR
| MB_OK
);
321 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, -1);
325 /* Check admin passwords */
326 GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15);
327 GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15);
328 if (_tcscmp(Password1
, Password2
))
331 _T("The passwords you entered do not match. Please enter "\
332 "the desired password again."),
334 MB_ICONERROR
| MB_OK
);
335 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, -1);
339 /* FIXME: check password for invalid characters */
341 /* FIXME: Set admin password */
359 SetKeyboardLayoutName(HWND hwnd
)
362 WCHAR szLayoutPath
[256];
363 WCHAR szLocaleName
[32];
367 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
368 L
"SYSTEM\\CurrentControlSet\\Control\\NLS\\Locale",
374 dwValueSize
= 16 * sizeof(WCHAR
);
375 if (RegQueryValueExW(hKey
,
387 L
"SYSTEM\\CurrentControlSet\\Control\\KeyboardLayouts\\"
391 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
398 dwValueSize
= 32 * sizeof(WCHAR
);
399 if (RegQueryValueExW(hKey
,
420 // TCHAR Caption[256];
422 hDll
= LoadLibraryW(L
"intl.cpl");
424 ZeroMemory(&psp
, sizeof(PROPSHEETPAGE
));
425 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
426 psp
.dwFlags
= PSP_DEFAULT
;
427 psp
.hInstance
= hDll
;
428 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_LOCALEPAGE
);
429 psp
.pfnDlgProc
= GetProcAddress(hDll
, "LocalePageProc");
432 // LoadString(hDll, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
434 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
435 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
436 psh
.dwFlags
= PSH_PROPSHEETPAGE
; // | PSH_PROPTITLE;
437 psh
.hwndParent
= NULL
;
438 psh
.hInstance
= hDll
;
439 // psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON));
440 // psh.pszCaption = Caption;
452 LocalePageDlgProc(HWND hwndDlg
,
457 PSETUPDATA SetupData
;
459 /* Retrieve pointer to the global setup data */
460 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
466 /* Save pointer to the global setup data */
467 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
468 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
471 SetKeyboardLayoutName(GetDlgItem(hwndDlg
, IDC_LAYOUTTEXT
));
477 if (HIWORD(wParam
) == BN_CLICKED
)
479 switch (LOWORD(wParam
))
481 case IDC_CUSTOMLOCALE
:
492 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
497 /* Enable the Back and Next buttons */
498 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
519 InitTimeZoneList(HWND hwnd
)
521 WCHAR szKeyName
[256];
530 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
531 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
541 lError
= RegEnumKeyExW(hZonesKey
,
549 if (lError
!= ERROR_SUCCESS
&& lError
!= ERROR_MORE_DATA
)
552 if (RegOpenKeyExW(hZonesKey
,
559 dwValueSize
= 256 * sizeof(WCHAR
);
560 if (RegQueryValueExW(hZoneKey
,
567 RegCloseKey(hZoneKey
);
576 RegCloseKey(hZoneKey
);
581 RegCloseKey(hZonesKey
);
615 SetLocalDateTime(HWND hwnd
)
619 SYSTEMTIME SystemTime
;
621 if (DateTime_GetSystemTime(GetDlgItem(hwnd
, IDC_DATEPICKER
), &Date
) == GDT_VALID
)
623 if (DateTime_GetSystemTime(GetDlgItem(hwnd
, IDC_TIMEPICKER
), &Time
) == GDT_VALID
)
625 SystemTime
.wYear
= Date
.wYear
;
626 SystemTime
.wMonth
= Date
.wMonth
;
627 SystemTime
.wDayOfWeek
= Date
.wDayOfWeek
;
628 SystemTime
.wDay
= Date
.wDay
;
629 SystemTime
.wHour
= Time
.wHour
;
630 SystemTime
.wMinute
= Time
.wMinute
;
631 SystemTime
.wSecond
= Time
.wSecond
;
632 SystemTime
.wMilliseconds
= Time
.wMilliseconds
;
634 SetLocalTime(&SystemTime
);
641 DateTimePageDlgProc(HWND hwndDlg
,
646 PSETUPDATA SetupData
;
648 /* Retrieve pointer to the global setup data */
649 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
655 /* Save pointer to the global setup data */
656 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
657 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
659 InitTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
));
666 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
671 /* Enable the Back and Next buttons */
672 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
677 // SetTimeZoneInformation();
679 SetLocalDateTime(hwndDlg
);
698 ProcessPageDlgProc(HWND hwndDlg
,
703 PSETUPDATA SetupData
;
705 /* Retrieve pointer to the global setup data */
706 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
712 /* Save pointer to the global setup data */
713 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
714 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
723 hWndProgress
= GetDlgItem(hwndDlg
, IDC_PROCESSPROGRESS
);
724 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
727 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_NEXT
);
731 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
738 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
743 /* Disable the Back and Next buttons */
744 PropSheet_SetWizButtons(GetParent(hwndDlg
), 0);
746 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETRANGE
, 0,
748 SetTimer(hwndDlg
, 0, 50, NULL
);
753 /* Enable the Back and Next buttons */
754 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
773 FinishDlgProc(HWND hwndDlg
,
783 PSETUPDATA SetupData
;
785 /* Get pointer to the global setup data */
786 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
789 SendDlgItemMessage(hwndDlg
,
792 (WPARAM
)SetupData
->hTitleFont
,
799 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
804 /* Enable the correct buttons on for the active page */
805 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_FINISH
);
809 /* Handle a Back button click, if necessary */
813 /* Handle a Finish button click, if necessary */
834 HPROPSHEETPAGE ahpsp
[6];
837 /* Clear setup data */
838 ZeroMemory(&SetupData
, sizeof(SETUPDATA
));
840 /* Create the Welcome page */
841 ZeroMemory (&psp
, sizeof(PROPSHEETPAGE
));
842 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
843 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
844 psp
.hInstance
= hDllInstance
;
845 psp
.lParam
= (LPARAM
)&SetupData
;
846 psp
.pfnDlgProc
= WelcomeDlgProc
;
847 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_WELCOMEPAGE
);
848 ahpsp
[0] = CreatePropertySheetPage(&psp
);
850 /* Create the Owner page */
851 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
852 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_OWNERTITLE
);
853 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_OWNERSUBTITLE
);
854 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_OWNERPAGE
);
855 psp
.pfnDlgProc
= OwnerPageDlgProc
;
856 ahpsp
[1] = CreatePropertySheetPage(&psp
);
858 /* Create the Computer page */
859 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
860 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_COMPUTERTITLE
);
861 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_COMPUTERSUBTITLE
);
862 psp
.pfnDlgProc
= ComputerPageDlgProc
;
863 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_COMPUTERPAGE
);
864 ahpsp
[2] = CreatePropertySheetPage(&psp
);
867 /* Create the Locale page */
868 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
869 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_LOCALETITLE
);
870 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_LOCALESUBTITLE
);
871 psp
.pfnDlgProc
= LocalePageDlgProc
;
872 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_LOCALEPAGE
);
873 ahpsp
[3] = CreatePropertySheetPage(&psp
);
876 /* Create the DateTime page */
877 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
878 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_DATETIMETITLE
);
879 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_DATETIMESUBTITLE
);
880 psp
.pfnDlgProc
= DateTimePageDlgProc
;
881 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_DATETIMEPAGE
);
882 ahpsp
[4] = CreatePropertySheetPage(&psp
);
885 /* Create the Process page */
886 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
887 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_PROCESSTITLE
);
888 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_PROCESSSUBTITLE
);
889 psp
.pfnDlgProc
= ProcessPageDlgProc
;
890 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROCESSPAGE
);
891 ahpsp
[5] = CreatePropertySheetPage(&psp
);
894 /* Create the Finish page */
895 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
896 psp
.pfnDlgProc
= FinishDlgProc
;
897 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_FINISHPAGE
);
898 ahpsp
[6] = CreatePropertySheetPage(&psp
);
900 /* Create the property sheet */
901 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
902 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
| PSH_HEADER
;
903 psh
.hInstance
= hDllInstance
;
904 psh
.hwndParent
= NULL
;
908 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
909 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
911 /* Create title font */
912 SetupData
.hTitleFont
= CreateTitleFont();
914 /* Display the wizard */
917 DeleteObject(SetupData
.hTitleFont
);