📄 wizard.c
字号:
WCHAR ErrorName[256];
LPNMHDR lpnm;
switch (uMsg)
{
case WM_INITDIALOG:
{
SendDlgItemMessage(hwndDlg, IDC_OWNERNAME, EM_LIMITTEXT, 50, 0);
SendDlgItemMessage(hwndDlg, IDC_OWNERORGANIZATION, EM_LIMITTEXT, 50, 0);
/* Set focus to owner name */
SetFocus(GetDlgItem(hwndDlg, IDC_OWNERNAME));
}
break;
case WM_NOTIFY:
{
lpnm = (LPNMHDR)lParam;
switch (lpnm->code)
{
case PSN_SETACTIVE:
/* Enable the Back and Next buttons */
PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
if (SetupData.UnattendSetup)
{
SendMessage(GetDlgItem(hwndDlg, IDC_OWNERNAME), WM_SETTEXT, 0, (LPARAM)SetupData.OwnerName);
SendMessage(GetDlgItem(hwndDlg, IDC_OWNERORGANIZATION), WM_SETTEXT, 0, (LPARAM)SetupData.OwnerOrganization);
if (WriteOwnerSettings(SetupData.OwnerName, SetupData.OwnerOrganization))
{
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_COMPUTERPAGE);
return TRUE;
}
}
break;
case PSN_WIZNEXT:
OwnerName[0] = 0;
if (GetDlgItemText(hwndDlg, IDC_OWNERNAME, OwnerName, 50) == 0)
{
if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
{
wcscpy(Title, L"ReactOS Setup");
}
if (0 == LoadStringW(hDllInstance, IDS_WZD_NAME, ErrorName, sizeof(ErrorName) / sizeof(ErrorName[0])))
{
wcscpy(ErrorName, L"Setup cannot continue until you enter your name.");
}
MessageBox(hwndDlg, ErrorName, Title, MB_ICONERROR | MB_OK);
SetFocus(GetDlgItem(hwndDlg, IDC_OWNERNAME));
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
return TRUE;
}
OwnerOrganization[0] = 0;
GetDlgItemTextW(hwndDlg, IDC_OWNERORGANIZATION, OwnerOrganization, 50);
if (!WriteOwnerSettings(OwnerName, OwnerOrganization))
{
SetFocus(GetDlgItem(hwndDlg, IDC_OWNERNAME));
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
return TRUE;
}
case PSN_WIZBACK:
SetupData.UnattendSetup = FALSE;
break;
default:
break;
}
}
break;
default:
break;
}
return FALSE;
}
static
BOOL
WriteComputerSettings(TCHAR * ComputerName, HWND hwndDlg)
{
WCHAR Title[64];
WCHAR ErrorComputerName[256];
if (!SetComputerName(ComputerName))
{
if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
{
wcscpy(Title, L"ReactOS Setup");
}
if (0 == LoadStringW(hDllInstance, IDS_WZD_SETCOMPUTERNAME, ErrorComputerName,
sizeof(ErrorComputerName) / sizeof(ErrorComputerName[0])))
{
wcscpy(ErrorComputerName, L"Setup failed to set the computer name.");
}
MessageBox(hwndDlg, ErrorComputerName, Title, MB_ICONERROR | MB_OK);
return FALSE;
}
/* Try to also set DNS hostname */
SetComputerNameEx(ComputerNamePhysicalDnsHostname, ComputerName);
return TRUE;
}
static INT_PTR CALLBACK
ComputerPageDlgProc(HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
TCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
TCHAR Password1[15];
TCHAR Password2[15];
PWCHAR Password;
WCHAR Title[64];
WCHAR EmptyComputerName[256], NotMatchPassword[256], WrongPassword[256];
DWORD Length;
LPNMHDR lpnm;
if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
{
wcscpy(Title, L"ReactOS Setup");
}
switch (uMsg)
{
case WM_INITDIALOG:
{
/* Retrieve current computer name */
Length = MAX_COMPUTERNAME_LENGTH + 1;
GetComputerName(ComputerName, &Length);
/* Display current computer name */
SetDlgItemText(hwndDlg, IDC_COMPUTERNAME, ComputerName);
/* Set text limits */
SendDlgItemMessage(hwndDlg, IDC_COMPUTERNAME, EM_LIMITTEXT, 64, 0);
SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD1, EM_LIMITTEXT, 14, 0);
SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD2, EM_LIMITTEXT, 14, 0);
/* Set focus to computer name */
SetFocus(GetDlgItem(hwndDlg, IDC_COMPUTERNAME));
if (SetupData.UnattendSetup)
{
SendMessage(GetDlgItem(hwndDlg, IDC_COMPUTERNAME), WM_SETTEXT, 0, (LPARAM)SetupData.ComputerName);
SendMessage(GetDlgItem(hwndDlg, IDC_ADMINPASSWORD1), WM_SETTEXT, 0, (LPARAM)SetupData.AdminPassword);
SendMessage(GetDlgItem(hwndDlg, IDC_ADMINPASSWORD2), WM_SETTEXT, 0, (LPARAM)SetupData.AdminPassword);
}
}
break;
case WM_NOTIFY:
{
lpnm = (LPNMHDR)lParam;
switch (lpnm->code)
{
case PSN_SETACTIVE:
/* Enable the Back and Next buttons */
PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
if (SetupData.UnattendSetup && WriteComputerSettings(SetupData.ComputerName, hwndDlg))
{
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_LOCALEPAGE);
return TRUE;
}
break;
case PSN_WIZNEXT:
if (GetDlgItemText(hwndDlg, IDC_COMPUTERNAME, ComputerName, 64) == 0)
{
if (0 == LoadStringW(hDllInstance, IDS_WZD_COMPUTERNAME, EmptyComputerName,
sizeof(EmptyComputerName) / sizeof(EmptyComputerName[0])))
{
wcscpy(EmptyComputerName, L"Setup cannot continue until you enter the name of your computer.");
}
MessageBox(hwndDlg, EmptyComputerName, Title, MB_ICONERROR | MB_OK);
SetFocus(GetDlgItem(hwndDlg, IDC_COMPUTERNAME));
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
return TRUE;
}
/* No need to check computer name for invalid characters,
* SetComputerName() will do it for us */
if (!WriteComputerSettings(ComputerName, hwndDlg))
{
SetFocus(GetDlgItem(hwndDlg, IDC_COMPUTERNAME));
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
return TRUE;
}
#if 0
/* Check if admin passwords have been entered */
if ((GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD1, Password1, 15) == 0) ||
(GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD2, Password2, 15) == 0))
{
if (0 == LoadStringW(hDllInstance, IDS_WZD_PASSWORDEMPTY, EmptyPassword,
sizeof(EmptyPassword) / sizeof(EmptyPassword[0])))
{
wcscpy(EmptyPassword, L"You must enter a password !");
}
MessageBox(hwndDlg, EmptyPassword, Title, MB_ICONERROR | MB_OK);
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
return TRUE;
}
#else
GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD1, Password1, 15);
GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD2, Password2, 15);
#endif
/* Check if passwords match */
if (_tcscmp(Password1, Password2))
{
if (0 == LoadStringW(hDllInstance, IDS_WZD_PASSWORDMATCH, NotMatchPassword,
sizeof(NotMatchPassword) / sizeof(NotMatchPassword[0])))
{
wcscpy(NotMatchPassword, L"The passwords you entered do not match. Please enter the desired password again.");
}
MessageBox(hwndDlg, NotMatchPassword, Title, MB_ICONERROR | MB_OK);
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
return TRUE;
}
/* Check password for invalid characters */
Password = (PWCHAR)Password1;
while (*Password)
{
if (!isprint(*Password))
{
if (0 == LoadStringW(hDllInstance, IDS_WZD_PASSWORDCHAR, WrongPassword,
sizeof(WrongPassword) / sizeof(WrongPassword[0])))
{
wcscpy(WrongPassword, L"The password you entered contains invalid characters. Please enter a cleaned password.");
}
MessageBox(hwndDlg, WrongPassword, Title, MB_ICONERROR | MB_OK);
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
return TRUE;
break;
}
Password++;
}
/* FIXME: Set admin password */
break;
case PSN_WIZBACK:
SetupData.UnattendSetup = FALSE;
break;
default:
break;
}
}
break;
default:
break;
}
return FALSE;
}
static VOID
SetKeyboardLayoutName(HWND hwnd)
{
#if 0
TCHAR szLayoutPath[256];
TCHAR szLocaleName[32];
DWORD dwLocaleSize;
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Locale"),
0,
KEY_ALL_ACCESS,
&hKey))
return;
dwValueSize = 16 * sizeof(TCHAR);
if (RegQueryValueEx(hKey,
NULL,
NULL,
NULL,
szLocaleName,
&dwLocaleSize))
{
RegCloseKey(hKey);
return;
}
_tcscpy(szLayoutPath,
_T("SYSTEM\\CurrentControlSet\\Control\\KeyboardLayouts\\"));
_tcscat(szLayoutPath,
szLocaleName);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
szLayoutPath,
0,
KEY_ALL_ACCESS,
&hKey))
return;
dwValueSize = 32 * sizeof(TCHAR);
if (RegQueryValueEx(hKey,
_T("Layout Text"),
NULL,
NULL,
szLocaleName,
&dwLocaleSize))
{
RegCloseKey(hKey);
return;
}
RegCloseKey(hKey);
#endif
}
static BOOL
RunControlPanelApplet(HWND hwnd, TCHAR *lpCommandLine)
{
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInformation;
ZeroMemory(&StartupInfo, sizeof(STARTUPINFO));
StartupInfo.cb = sizeof(STARTUPINFO);
if (!CreateProcess(NULL,
lpCommandLine,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&StartupInfo,
&ProcessInformation))
{
MessageBox(hwnd, _T("Error: failed to launch rundll32"), _T("Error"), MB_ICONERROR);
return FALSE;
}
WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
CloseHandle(ProcessInformation.hThread);
CloseHandle(ProcessInformation.hProcess);
return TRUE;
}
static INT_PTR CALLBACK
LocalePageDlgProc(HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
PSETUPDATA SetupData;
TCHAR szBuffer[MAX_PATH];
/* Retrieve pointer to the global setup data */
SetupData = (PSETUPDATA)GetWindowLongPtr (hwndDlg, GWL_USERDATA);
switch (uMsg)
{
case WM_INITDIALOG:
{
/* Save pointer to the global setup data */
SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
SetWindowLongPtr(hwndDlg, GWL_USERDATA, (DWORD_PTR)SetupData);
SetKeyboardLayoutName(GetDlgItem(hwndDlg, IDC_LAYOUTTEXT));
}
break;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
{
switch (LOWORD(wParam))
{
case IDC_CUSTOMLOCALE:
{
_tcscpy(szBuffer, _T("rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,5"));
RunControlPanelApplet(hwndDlg, szBuffer);
/* FIXME: Update input locale name */
}
break;
case IDC_CUSTOMLAYOUT:
{
_tcscpy(szBuffer, _T("rundll32.exe shell32.dll,Control_RunDLL main.cpl,@1"));
RunControlPanelApplet(hwndDlg, szBuffer);
}
break;
}
}
break;
case WM_NOTIFY:
{
LPNMHDR lpnm = (LPNMHDR)lParam;
switch (lpnm->code)
{
case PSN_SETACTIVE:
/* Enable the Back and Next buttons */
PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
if (SetupData->UnattendSetup)
{
_tcscpy(szBuffer, _T("rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,/f:\"unattend.inf\""));
RunControlPanelApplet(hwndDlg, szBuffer);
SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_DATETIMEPAGE);
return TRUE;
}
break;
case PSN_WIZNEXT:
break;
case PSN_WIZBACK:
SetupData->UnattendSetup = FALSE;
break;
default:
break;
}
}
break;
default:
break;
}
return FALSE;
}
static PTIMEZONE_ENTRY
GetLargerTimeZoneEntry(PSETUPDATA SetupData, DWORD Index)
{
PTIMEZONE_ENTRY Entry;
Entry = SetupData->TimeZoneListHead;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -