[PSDK][REACTOS] Fix definitions and usage of DWLP_MSGRESULT, DWLP_DLGPROC, and DWLP_USER
[reactos.git] / dll / shellext / netshell / setup.cpp
1 #include "precomp.h"
2
3 #include <syssetup/syssetup.h>
4
5
6 #define NETWORK_SETUP_MAGIC 0x50515253
7
8 typedef struct _NETWORKSETUPDATA
9 {
10 DWORD dwMagic;
11 BOOL bTypicalNetworkSetup;
12
13
14 PSETUPDATA pSetupData;
15 } NETWORKSETUPDATA, *PNETWORKSETUPDATA;
16
17
18 extern "C"
19 {
20
21 static
22 VOID
23 SetBoldText(
24 HWND hwndDlg,
25 INT control,
26 PSETUPDATA pSetupData)
27 {
28 SendDlgItemMessageW(hwndDlg, control, WM_SETFONT, (WPARAM)pSetupData->hBoldFont, MAKELPARAM(TRUE, 0));
29 }
30
31 static
32 INT_PTR
33 CALLBACK
34 NetworkSettingsPageDlgProc(
35 HWND hwndDlg,
36 UINT uMsg,
37 WPARAM wParam,
38 LPARAM lParam)
39 {
40 PNETWORKSETUPDATA pNetworkSetupData;
41 PSETUPDATA pSetupData;
42 LPNMHDR lpnm;
43
44 /* Retrieve pointer to the global setup data */
45 pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
46 if ((pNetworkSetupData != NULL) &&
47 (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
48 pSetupData = pNetworkSetupData->pSetupData;
49
50 switch (uMsg)
51 {
52 case WM_INITDIALOG:
53 /* Save pointer to the global setup data */
54 pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
55 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
56 pSetupData = pNetworkSetupData->pSetupData;
57
58 /* Set the fonts of both the options to bold */
59 SetBoldText(hwndDlg, IDC_NETWORK_TYPICAL, pSetupData);
60 SetBoldText(hwndDlg, IDC_NETWORK_CUSTOM, pSetupData);
61
62 /* Set the typical settings option as the default */
63 SendDlgItemMessage(hwndDlg, IDC_NETWORK_TYPICAL, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
64
65 if (pSetupData->UnattendSetup)
66 {
67 //...
68 }
69 break;
70
71 case WM_DESTROY:
72 /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
73 //...
74 break;
75
76 case WM_NOTIFY:
77 lpnm = (LPNMHDR)lParam;
78
79 switch (lpnm->code)
80 {
81 case PSN_SETACTIVE:
82 /* Enable the Back and Next buttons */
83 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
84 if (pSetupData->UnattendSetup)
85 {
86 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKCOMPONENTPAGE);
87 return TRUE;
88 }
89 break;
90
91 case PSN_WIZNEXT:
92 pNetworkSetupData->bTypicalNetworkSetup = FALSE;
93
94 /* If the Typical Settings button is chosen, then skip to the Domain Page */
95 if (IsDlgButtonChecked(hwndDlg, IDC_NETWORK_TYPICAL) == BST_CHECKED)
96 {
97 pNetworkSetupData->bTypicalNetworkSetup = TRUE;
98 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKDOMAINPAGE);
99 return TRUE;
100 }
101 break;
102
103 case PSN_WIZBACK:
104 pSetupData->UnattendSetup = FALSE;
105 break;
106 }
107 break;
108
109 default:
110 break;
111 }
112
113 return FALSE;
114 }
115
116 static
117 INT_PTR
118 CALLBACK
119 NetworkComponentPageDlgProc(
120 HWND hwndDlg,
121 UINT uMsg,
122 WPARAM wParam,
123 LPARAM lParam)
124 {
125 PNETWORKSETUPDATA pNetworkSetupData;
126 PSETUPDATA pSetupData;
127 LPNMHDR lpnm;
128
129 /* Retrieve pointer to the global setup data */
130 pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
131 if ((pNetworkSetupData != NULL) &&
132 (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
133 pSetupData = pNetworkSetupData->pSetupData;
134
135 switch (uMsg)
136 {
137 case WM_INITDIALOG:
138 /* Save pointer to the global setup data */
139 pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
140 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
141 pSetupData = pNetworkSetupData->pSetupData;
142
143 SetBoldText(hwndDlg, IDC_NETWORK_DEVICE, pSetupData);
144
145 if (pSetupData->UnattendSetup)
146 {
147 //...
148 }
149 break;
150
151 case WM_DESTROY:
152 /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
153 //...
154 break;
155
156 case WM_NOTIFY:
157 lpnm = (LPNMHDR)lParam;
158
159 switch (lpnm->code)
160 {
161 case PSN_SETACTIVE:
162 /* Enable the Back and Next buttons */
163 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
164 if (pSetupData->UnattendSetup)
165 {
166 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKDOMAINPAGE);
167 return TRUE;
168 }
169 break;
170
171 case PSN_WIZBACK:
172 pSetupData->UnattendSetup = FALSE;
173 break;
174 }
175 break;
176
177 default:
178 break;
179 }
180
181 return FALSE;
182 }
183
184 static
185 INT_PTR
186 CALLBACK
187 NetworkDomainPageDlgProc(
188 HWND hwndDlg,
189 UINT uMsg,
190 WPARAM wParam,
191 LPARAM lParam)
192 {
193 PNETWORKSETUPDATA pNetworkSetupData;
194 PSETUPDATA pSetupData;
195 WCHAR DomainName[51];
196 WCHAR Title[64];
197 WCHAR ErrorName[256];
198 LPNMHDR lpnm;
199
200 /* Retrieve pointer to the global setup data */
201 pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
202 if ((pNetworkSetupData != NULL) &&
203 (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
204 pSetupData = pNetworkSetupData->pSetupData;
205
206 switch (uMsg)
207 {
208 case WM_INITDIALOG:
209 /* Save pointer to the global setup data */
210 pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
211 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
212 pSetupData = pNetworkSetupData->pSetupData;
213
214 /* Set the workgroup option as the default */
215 SendDlgItemMessage(hwndDlg, IDC_SELECT_WORKGROUP, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
216
217 wcscpy(DomainName, L"WORKGROUP");
218
219 /* Display current computer name */
220 SetDlgItemTextW(hwndDlg, IDC_DOMAIN_NAME, DomainName);
221
222 /* Set focus to owner name */
223 SetFocus(GetDlgItem(hwndDlg, IDC_DOMAIN_NAME));
224
225 if (pSetupData->UnattendSetup)
226 {
227 //...
228 }
229 break;
230
231 case WM_DESTROY:
232 //...
233 /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
234 if (pNetworkSetupData != NULL)
235 {
236 if ((!IsBadReadPtr(pNetworkSetupData, sizeof(NETWORKSETUPDATA))) &&
237 (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
238 HeapFree(GetProcessHeap(), 0, pNetworkSetupData);
239
240 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)NULL);
241 }
242 break;
243
244 case WM_NOTIFY:
245 lpnm = (LPNMHDR)lParam;
246
247 switch (lpnm->code)
248 {
249 case PSN_SETACTIVE:
250 /* Enable the Back and Next buttons */
251 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
252 if (pSetupData->UnattendSetup)
253 {
254 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, pSetupData->uPostNetworkWizardPage);
255 return TRUE;
256 }
257 break;
258
259 case PSN_WIZNEXT:
260 DomainName[0] = 0;
261 if (GetDlgItemTextW(hwndDlg, IDC_DOMAIN_NAME, DomainName, 50) == 0)
262 {
263 if (0 == LoadStringW(netshell_hInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
264 {
265 wcscpy(Title, L"ReactOS Setup");
266 }
267 if (0 == LoadStringW(netshell_hInstance, IDS_WZD_DOMAIN_NAME, ErrorName, sizeof(ErrorName) / sizeof(ErrorName[0])))
268 {
269 wcscpy(ErrorName, L"Setup cannot continue until you\nenter the name of your domain/workgroup.");
270 }
271 MessageBoxW(hwndDlg, ErrorName, Title, MB_ICONERROR | MB_OK);
272
273 SetFocus(GetDlgItem(hwndDlg, IDC_DOMAIN_NAME));
274 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
275
276 //TODO: Implement setting the Domain/Workgroup
277
278 return TRUE;
279 }
280 break;
281
282 case PSN_WIZBACK:
283 pSetupData->UnattendSetup = FALSE;
284
285 /* If the Typical setup chosen, then skip back to the Settings Page */
286 if (pNetworkSetupData->bTypicalNetworkSetup == TRUE)
287 {
288 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKSETTINGSPAGE);
289 return TRUE;
290 }
291 break;
292 }
293 break;
294
295 default:
296 break;
297 }
298
299 return FALSE;
300 }
301
302
303 DWORD
304 WINAPI
305 NetSetupRequestWizardPages(
306 PDWORD pPageCount,
307 HPROPSHEETPAGE *pPages,
308 PSETUPDATA pSetupData)
309 {
310 PNETWORKSETUPDATA pNetworkSetupData;
311 PROPSHEETPAGE psp = {0};
312 DWORD dwPageCount = 3;
313 INT nPage = 0;
314
315 if (pPageCount == NULL)
316 return ERROR_INVALID_PARAMETER;
317
318 if (pPages == NULL)
319 {
320 *pPageCount = dwPageCount;
321 return ERROR_SUCCESS;
322 }
323
324 if (*pPageCount < dwPageCount)
325 return ERROR_BUFFER_OVERFLOW;
326
327 pSetupData->uFirstNetworkWizardPage = IDD_NETWORKSETTINGSPAGE;
328
329 pNetworkSetupData = (PNETWORKSETUPDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(NETWORKSETUPDATA));
330 if (pNetworkSetupData == NULL)
331 return ERROR_OUTOFMEMORY;
332
333 pNetworkSetupData->dwMagic = NETWORK_SETUP_MAGIC;
334 pNetworkSetupData->pSetupData = pSetupData;
335
336
337 /* Create the Network Settings page */
338 psp.dwSize = sizeof(PROPSHEETPAGE);
339 psp.hInstance = netshell_hInstance;
340 psp.lParam = (LPARAM)pNetworkSetupData;
341
342 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
343 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKSETTINGSTITLE);
344 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKSETTINGSSUBTITLE);
345 psp.pfnDlgProc = NetworkSettingsPageDlgProc;
346 psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKSETTINGSPAGE);
347 pPages[nPage++] = CreatePropertySheetPage(&psp);
348
349 /* Create the Network Components page */
350 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
351 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKCOMPONENTTITLE);
352 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKCOMPONENTSUBTITLE);
353 psp.pfnDlgProc = NetworkComponentPageDlgProc;
354 psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKCOMPONENTPAGE);
355 pPages[nPage++] = CreatePropertySheetPage(&psp);
356
357 /* Create the Domain/Workgroup page */
358 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
359 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKDOMAINTITLE);
360 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKDOMAINSUBTITLE);
361 psp.pfnDlgProc = NetworkDomainPageDlgProc;
362 psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKDOMAINPAGE);
363 pPages[nPage++] = CreatePropertySheetPage(&psp);
364
365 *pPageCount = dwPageCount;
366
367 return ERROR_SUCCESS;
368 }
369
370 } // extern "C"