1 /*
2 * PROJECT: ReactOS Applications
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/msconfig_new/generalpage.c
5 * PURPOSE: General page message handler
6 * COPYRIGHT: Copyright 2005-2006 Christoph von Wittich <Christoph@ApiViewer.de>
7 * Copyright 2011-2012 Hermes BELUSCA - MAITO <hermes.belusca@sfr.fr>
8 */
9
10 #include "precomp.h"
11 #include "fileutils.h"
12 #include "utils.h"
13 #include "comctl32supp.h"
14 #include "fileextractdialog.h"
15
16 static LPCWSTR lpszRestoreProgPath1 = L"%SystemRoot%\\System32\\rstrui.exe";
17 static LPCWSTR lpszRestoreProgPath2 = L"%SystemRoot%\\System32\\restore\\rstrui.exe";
18
19 static HWND hGeneralPage = NULL;
20 static BOOL bIsOriginalBootIni = TRUE;
21 // static BOOL bIsStartupNotModified = TRUE;
22
EnableSelectiveStartupControls(BOOL bEnable)23 static VOID EnableSelectiveStartupControls(BOOL bEnable)
24 {
25 assert(hGeneralPage);
26
27 EnableWindow(GetDlgItem(hGeneralPage, IDC_CBX_LOAD_SYSTEM_SERVICES), bEnable);
28 EnableWindow(GetDlgItem(hGeneralPage, IDC_CBX_LOAD_STARTUP_ITEMS) , bEnable);
29
30 EnableWindow(GetDlgItem(hGeneralPage, IDC_CBX_USE_ORIGINAL_BOOTCFG), bEnable);
31
32 // EnableWindow(GetDlgItem(hGeneralPage, IDC_RB_USE_ORIGINAL_BOOTCAT), bEnable);
33 // EnableWindow(GetDlgItem(hGeneralPage, IDC_RB_USE_MODIFIED_BOOTCAT), (bEnable ? !bIsOriginalBootIni : FALSE));
34
35 EnableWindow(GetDlgItem(hGeneralPage, IDC_CBX_SYSTEM_INI), bEnable);
36 EnableWindow(GetDlgItem(hGeneralPage, IDC_CBX_WIN_INI) , bEnable);
37
38 return;
39 }
40
CheckSelectiveStartupControls(BOOL bCheck)41 static VOID CheckSelectiveStartupControls(BOOL bCheck)
42 {
43 assert(hGeneralPage);
44
45 Button_SetCheck(GetDlgItem(hGeneralPage, IDC_CBX_LOAD_SYSTEM_SERVICES), (bCheck ? BST_CHECKED : BST_UNCHECKED));
46 Button_SetCheck(GetDlgItem(hGeneralPage, IDC_CBX_LOAD_STARTUP_ITEMS) , (bCheck ? BST_CHECKED : BST_UNCHECKED));
47 Button_SetCheck(GetDlgItem(hGeneralPage, IDC_CBX_USE_ORIGINAL_BOOTCFG), (bCheck ? BST_CHECKED : BST_UNCHECKED));
48 Button_SetCheck(GetDlgItem(hGeneralPage, IDC_CBX_SYSTEM_INI) , (bCheck ? BST_CHECKED : BST_UNCHECKED));
49 Button_SetCheck(GetDlgItem(hGeneralPage, IDC_CBX_WIN_INI) , (bCheck ? BST_CHECKED : BST_UNCHECKED));
50
51 return;
52 }
53
54 INT_PTR CALLBACK
GeneralPageWndProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)55 GeneralPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
56 {
57 UNREFERENCED_PARAMETER(lParam);
58
59 switch (message)
60 {
61 case WM_INITDIALOG:
62 {
63 hGeneralPage = hDlg;
64 PropSheet_UnChanged(GetParent(hGeneralPage), hGeneralPage);
65
66 /* Search for the restore program and enable its button if needed */
67 if ( MyFileExists(lpszRestoreProgPath1, NULL) ||
68 MyFileExists(lpszRestoreProgPath2, NULL) )
69 Button_Enable(GetDlgItem(hGeneralPage, IDC_BTN_SYSTEM_RESTORE_START), TRUE);
70 else
71 Button_Enable(GetDlgItem(hGeneralPage, IDC_BTN_SYSTEM_RESTORE_START), FALSE);
72
73 #if 0
74 /* FIXME */
75 SendDlgItemMessage(hDlg, IDC_RB_NORMAL_STARTUP, BM_SETCHECK, BST_CHECKED, 0);
76 EnableCheckboxControls(hDlg, FALSE);
77 #endif
78
79 return TRUE;
80 }
81
82 case WM_COMMAND:
83 {
84 switch (LOWORD(wParam))
85 {
86 case IDC_RB_NORMAL_STARTUP:
87 {
88 /* Be sure that only this button is activated and the others are not */
89 CheckRadioButton(hGeneralPage, IDC_RB_NORMAL_STARTUP, IDC_RB_SELECTIVE_STARTUP, IDC_RB_NORMAL_STARTUP);
90
91 bIsOriginalBootIni = TRUE;
92 EnableSelectiveStartupControls(FALSE);
93 CheckSelectiveStartupControls(TRUE);
94
95 Button_SetCheck(GetDlgItem(hGeneralPage, IDC_CBX_USE_ORIGINAL_BOOTCFG), (bIsOriginalBootIni ? BST_CHECKED : BST_UNCHECKED));
96
97 PropSheet_Changed(GetParent(hGeneralPage), hGeneralPage);
98 break;
99 }
100
101 case IDC_RB_DIAGNOSTIC_STARTUP:
102 {
103 /* Be sure that only this button is activated and the others are not */
104 CheckRadioButton(hGeneralPage, IDC_RB_NORMAL_STARTUP, IDC_RB_SELECTIVE_STARTUP, IDC_RB_DIAGNOSTIC_STARTUP);
105
106 EnableSelectiveStartupControls(FALSE);
107 CheckSelectiveStartupControls(FALSE);
108
109 PropSheet_Changed(GetParent(hGeneralPage), hGeneralPage);
110 break;
111 }
112
113 case IDC_RB_SELECTIVE_STARTUP:
114 {
115 /* Be sure that only this button is activated and the others are not */
116 CheckRadioButton(hGeneralPage, IDC_RB_NORMAL_STARTUP, IDC_RB_SELECTIVE_STARTUP, IDC_RB_SELECTIVE_STARTUP);
117
118 EnableSelectiveStartupControls(TRUE);
119 PropSheet_Changed(GetParent(hGeneralPage), hGeneralPage);
120
121 break;
122 }
123
124 case IDC_CBX_USE_ORIGINAL_BOOTCFG:
125 {
126 bIsOriginalBootIni = TRUE;
127
128 Button_SetCheck(GetDlgItem(hGeneralPage, IDC_CBX_USE_ORIGINAL_BOOTCFG), (bIsOriginalBootIni ? BST_CHECKED : BST_UNCHECKED));
129 EnableWindow(GetDlgItem(hGeneralPage, IDC_CBX_USE_ORIGINAL_BOOTCFG), !bIsOriginalBootIni /*FALSE*/);
130
131 PropSheet_Changed(GetParent(hGeneralPage), hGeneralPage);
132
133 break;
134 }
135
136 case IDC_BTN_SYSTEM_RESTORE_START:
137 {
138 // NOTE: 'err' variable defined for debugging purposes only.
139 DWORD err = RunCommand(lpszRestoreProgPath1, NULL, SW_SHOW);
140 if (err == ERROR_FILE_NOT_FOUND)
141 err = RunCommand(lpszRestoreProgPath2, NULL, SW_SHOW);
142
143 break;
144 }
145
146 case IDC_BTN_FILE_EXTRACTION:
147 DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_FILE_EXTRACT_DIALOG), hGeneralPage /* GetParent(hGeneralPage) */, FileExtractDialogWndProc);
148 break;
149
150 default:
151 //break;
152 return FALSE;
153 }
154 break;
155 }
156
157 case WM_NOTIFY:
158 {
159 switch (((LPNMHDR)lParam)->code)
160 {
161 case PSN_APPLY:
162 {
163 // TODO: Try to apply the modifications to the system.
164 PropSheet_UnChanged(GetParent(hGeneralPage), hGeneralPage);
165 return TRUE;
166 }
167
168 case PSN_HELP:
169 {
170 MessageBoxW(hGeneralPage, L"Help not implemented yet!", L"Help", MB_ICONINFORMATION | MB_OK);
171 return TRUE;
172 }
173
174 case PSN_KILLACTIVE: // Is going to lose activation.
175 {
176 // Changes are always valid of course.
177 SetWindowLongPtr(hGeneralPage, DWLP_MSGRESULT, FALSE);
178 return TRUE;
179 }
180
181 case PSN_QUERYCANCEL:
182 {
183 // Allows cancellation.
184 SetWindowLongPtr(hGeneralPage, DWLP_MSGRESULT, FALSE);
185 return TRUE;
186 }
187
188 case PSN_QUERYINITIALFOCUS:
189 {
190 // SetWindowLongPtr(hGeneralPage, DWLP_MSGRESULT,
191 // (LONG_PTR)GetDlgItem(hGeneralPage, (bIsOriginalBootIni ? IDC_RB_NORMAL_STARTUP : IDC_RB_SELECTIVE_STARTUP)));
192 return TRUE;
193 }
194
195 //
196 // DO NOT TOUCH THESE NEXT MESSAGES, THEY ARE OK LIKE THIS...
197 //
198 case PSN_RESET: // Perform final cleaning, called before WM_DESTROY.
199 return TRUE;
200
201 case PSN_SETACTIVE: // Is going to gain activation.
202 {
203 SetWindowLongPtr(hGeneralPage, DWLP_MSGRESULT, 0);
204 return TRUE;
205 }
206
207 default:
208 break;
209 }
210
211 return FALSE;
212 }
213
214 default:
215 return FALSE;
216 }
217
218 return FALSE;
219 }
220