ReactOS  0.4.13-dev-66-gc714b7f
setup.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Shell
3  * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE: ReactOS Networking Configuration
5  * COPYRIGHT: Copyright 2016 Eric Kohl
6  */
7 
8 #include "precomp.h"
9 
10 #include <syssetup/syssetup.h>
11 
12 
13 #define NETWORK_SETUP_MAGIC 0x50515253
14 
15 typedef struct _NETWORKSETUPDATA
16 {
19 
20 
23 
24 
25 extern "C"
26 {
27 
28 static
29 VOID
31  HWND hwndDlg,
32  INT control,
33  PSETUPDATA pSetupData)
34 {
35  SendDlgItemMessageW(hwndDlg, control, WM_SETFONT, (WPARAM)pSetupData->hBoldFont, MAKELPARAM(TRUE, 0));
36 }
37 
38 static
39 INT_PTR
42  HWND hwndDlg,
43  UINT uMsg,
44  WPARAM wParam,
45  LPARAM lParam)
46 {
47  PNETWORKSETUPDATA pNetworkSetupData;
48  PSETUPDATA pSetupData;
49  LPNMHDR lpnm;
50 
51  /* Retrieve pointer to the global setup data */
52  pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
53  if ((pNetworkSetupData != NULL) &&
54  (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
55  pSetupData = pNetworkSetupData->pSetupData;
56 
57  switch (uMsg)
58  {
59  case WM_INITDIALOG:
60  /* Save pointer to the global setup data */
61  pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
62  SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
63  pSetupData = pNetworkSetupData->pSetupData;
64 
65  /* Set the fonts of both the options to bold */
66  SetBoldText(hwndDlg, IDC_NETWORK_TYPICAL, pSetupData);
67  SetBoldText(hwndDlg, IDC_NETWORK_CUSTOM, pSetupData);
68 
69  /* Set the typical settings option as the default */
71 
72  if (pSetupData->UnattendSetup)
73  {
74  //...
75  }
76  break;
77 
78  case WM_DESTROY:
79  /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
80  //...
81  break;
82 
83  case WM_NOTIFY:
84  lpnm = (LPNMHDR)lParam;
85 
86  switch (lpnm->code)
87  {
88  case PSN_SETACTIVE:
89  /* Enable the Back and Next buttons */
91  if (pSetupData->UnattendSetup)
92  {
94  return TRUE;
95  }
96  break;
97 
98  case PSN_WIZNEXT:
99  pNetworkSetupData->bTypicalNetworkSetup = FALSE;
100 
101  /* If the Typical Settings button is chosen, then skip to the Domain Page */
103  {
104  pNetworkSetupData->bTypicalNetworkSetup = TRUE;
106  return TRUE;
107  }
108  break;
109 
110  case PSN_WIZBACK:
111  pSetupData->UnattendSetup = FALSE;
112  break;
113  }
114  break;
115 
116  default:
117  break;
118  }
119 
120  return FALSE;
121 }
122 
123 static
124 INT_PTR
125 CALLBACK
127  HWND hwndDlg,
128  UINT uMsg,
129  WPARAM wParam,
130  LPARAM lParam)
131 {
132  PNETWORKSETUPDATA pNetworkSetupData;
133  PSETUPDATA pSetupData;
134  LPNMHDR lpnm;
135 
136  /* Retrieve pointer to the global setup data */
137  pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
138  if ((pNetworkSetupData != NULL) &&
139  (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
140  pSetupData = pNetworkSetupData->pSetupData;
141 
142  switch (uMsg)
143  {
144  case WM_INITDIALOG:
145  /* Save pointer to the global setup data */
146  pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
147  SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
148  pSetupData = pNetworkSetupData->pSetupData;
149 
150  SetBoldText(hwndDlg, IDC_NETWORK_DEVICE, pSetupData);
151 
152  if (pSetupData->UnattendSetup)
153  {
154  //...
155  }
156  break;
157 
158  case WM_DESTROY:
159  /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
160  //...
161  break;
162 
163  case WM_NOTIFY:
164  lpnm = (LPNMHDR)lParam;
165 
166  switch (lpnm->code)
167  {
168  case PSN_SETACTIVE:
169  /* Enable the Back and Next buttons */
171  if (pSetupData->UnattendSetup)
172  {
174  return TRUE;
175  }
176  break;
177 
178  case PSN_WIZBACK:
179  pSetupData->UnattendSetup = FALSE;
180  break;
181  }
182  break;
183 
184  default:
185  break;
186  }
187 
188  return FALSE;
189 }
190 
191 static
192 INT_PTR
193 CALLBACK
195  HWND hwndDlg,
196  UINT uMsg,
197  WPARAM wParam,
198  LPARAM lParam)
199 {
200  PNETWORKSETUPDATA pNetworkSetupData;
201  PSETUPDATA pSetupData;
202  WCHAR DomainName[51];
203  WCHAR Title[64];
204  WCHAR ErrorName[256];
205  LPNMHDR lpnm;
206 
207  /* Retrieve pointer to the global setup data */
208  pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
209  if ((pNetworkSetupData != NULL) &&
210  (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
211  pSetupData = pNetworkSetupData->pSetupData;
212 
213  switch (uMsg)
214  {
215  case WM_INITDIALOG:
216  /* Save pointer to the global setup data */
217  pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
218  SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
219  pSetupData = pNetworkSetupData->pSetupData;
220 
221  /* Set the workgroup option as the default */
223 
224  wcscpy(DomainName, L"WORKGROUP");
225 
226  /* Display current computer name */
227  SetDlgItemTextW(hwndDlg, IDC_DOMAIN_NAME, DomainName);
228 
229  /* Set focus to owner name */
231 
232  if (pSetupData->UnattendSetup)
233  {
234  //...
235  }
236  break;
237 
238  case WM_DESTROY:
239  //...
240  /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
241  if (pNetworkSetupData != NULL)
242  {
243  if ((!IsBadReadPtr(pNetworkSetupData, sizeof(NETWORKSETUPDATA))) &&
244  (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
245  HeapFree(GetProcessHeap(), 0, pNetworkSetupData);
246 
248  }
249  break;
250 
251  case WM_NOTIFY:
252  lpnm = (LPNMHDR)lParam;
253 
254  switch (lpnm->code)
255  {
256  case PSN_SETACTIVE:
257  /* Enable the Back and Next buttons */
259  if (pSetupData->UnattendSetup)
260  {
262  return TRUE;
263  }
264  break;
265 
266  case PSN_WIZNEXT:
267  DomainName[0] = 0;
268  if (GetDlgItemTextW(hwndDlg, IDC_DOMAIN_NAME, DomainName, 50) == 0)
269  {
270  if (0 == LoadStringW(netshell_hInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
271  {
272  wcscpy(Title, L"ReactOS Setup");
273  }
274  if (0 == LoadStringW(netshell_hInstance, IDS_WZD_DOMAIN_NAME, ErrorName, sizeof(ErrorName) / sizeof(ErrorName[0])))
275  {
276  wcscpy(ErrorName, L"Setup cannot continue until you\nenter the name of your domain/workgroup.");
277  }
278  MessageBoxW(hwndDlg, ErrorName, Title, MB_ICONERROR | MB_OK);
279 
281  SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
282 
283  //TODO: Implement setting the Domain/Workgroup
284 
285  return TRUE;
286  }
287  break;
288 
289  case PSN_WIZBACK:
290  pSetupData->UnattendSetup = FALSE;
291 
292  /* If the Typical setup chosen, then skip back to the Settings Page */
293  if (pNetworkSetupData->bTypicalNetworkSetup == TRUE)
294  {
296  return TRUE;
297  }
298  break;
299  }
300  break;
301 
302  default:
303  break;
304  }
305 
306  return FALSE;
307 }
308 
309 
310 DWORD
311 WINAPI
313  PDWORD pPageCount,
314  HPROPSHEETPAGE *pPages,
315  PSETUPDATA pSetupData)
316 {
317  PNETWORKSETUPDATA pNetworkSetupData;
318  PROPSHEETPAGE psp = {0};
319  DWORD dwPageCount = 3;
320  INT nPage = 0;
321 
322  if (pPageCount == NULL)
324 
325  if (pPages == NULL)
326  {
327  *pPageCount = dwPageCount;
328  return ERROR_SUCCESS;
329  }
330 
331  if (*pPageCount < dwPageCount)
332  return ERROR_BUFFER_OVERFLOW;
333 
335 
337  if (pNetworkSetupData == NULL)
338  return ERROR_OUTOFMEMORY;
339 
340  pNetworkSetupData->dwMagic = NETWORK_SETUP_MAGIC;
341  pNetworkSetupData->pSetupData = pSetupData;
342 
343 
344  /* Create the Network Settings page */
345  psp.dwSize = sizeof(PROPSHEETPAGE);
347  psp.lParam = (LPARAM)pNetworkSetupData;
348 
349  psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
350  psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKSETTINGSTITLE);
351  psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKSETTINGSSUBTITLE);
352  psp.pfnDlgProc = NetworkSettingsPageDlgProc;
353  psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKSETTINGSPAGE);
354  pPages[nPage++] = CreatePropertySheetPage(&psp);
355 
356  /* Create the Network Components page */
357  psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
358  psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKCOMPONENTTITLE);
359  psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKCOMPONENTSUBTITLE);
360  psp.pfnDlgProc = NetworkComponentPageDlgProc;
361  psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKCOMPONENTPAGE);
362  pPages[nPage++] = CreatePropertySheetPage(&psp);
363 
364  /* Create the Domain/Workgroup page */
365  psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
366  psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKDOMAINTITLE);
367  psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKDOMAINSUBTITLE);
368  psp.pfnDlgProc = NetworkDomainPageDlgProc;
369  psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKDOMAINPAGE);
370  pPages[nPage++] = CreatePropertySheetPage(&psp);
371 
372  *pPageCount = dwPageCount;
373 
374  return ERROR_SUCCESS;
375 }
376 
377 } // extern "C"
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define MAKEINTRESOURCE
Definition: winuser.h:591
static INT_PTR CALLBACK NetworkDomainPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: setup.cpp:194
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2195
#define TRUE
Definition: types.h:120
#define IDS_NETWORKCOMPONENTTITLE
Definition: resource.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define IDS_NETWORKDOMAINTITLE
Definition: resource.h:122
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
struct _NETWORKSETUPDATA NETWORKSETUPDATA
#define IDS_REACTOS_SETUP
Definition: resource.h:124
#define MAKELPARAM(l, h)
Definition: winuser.h:3915
#define CALLBACK
Definition: compat.h:27
#define IDC_NETWORK_CUSTOM
Definition: resource.h:57
#define PSWIZB_NEXT
Definition: prsht.h:154
HWND WINAPI SetFocus(_In_opt_ HWND)
UINT_PTR WPARAM
Definition: windef.h:207
#define SendDlgItemMessage
Definition: winuser.h:5708
int32_t INT_PTR
Definition: typedefs.h:62
#define PSN_SETACTIVE
Definition: prsht.h:115
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
HINSTANCE netshell_hInstance
Definition: netshell.cpp:12
int32_t INT
Definition: typedefs.h:56
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
BOOL bTypicalNetworkSetup
Definition: setup.cpp:18
#define DWLP_MSGRESULT
Definition: winuser.h:864
struct tagNMHDR * LPNMHDR
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
UINT code
Definition: winuser.h:3112
#define IDC_NETWORK_DEVICE
Definition: resource.h:61
#define IDS_NETWORKSETTINGSTITLE
Definition: resource.h:118
unsigned int BOOL
Definition: ntddk_ex.h:94
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
#define IDC_SELECT_WORKGROUP
Definition: resource.h:67
#define GWLP_USERDATA
Definition: treelist.c:63
#define NETWORK_SETUP_MAGIC
Definition: setup.cpp:13
#define LPPROPSHEETPAGE
Definition: prsht.h:372
smooth NULL
Definition: ftsmooth.c:416
#define PSN_WIZNEXT
Definition: prsht.h:121
LONG_PTR LPARAM
Definition: windef.h:208
#define IDS_NETWORKSETTINGSSUBTITLE
Definition: resource.h:119
#define PropSheet_SetWizButtons(d, f)
Definition: prsht.h:339
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define CreatePropertySheetPage
Definition: prsht.h:381
#define WM_DESTROY
Definition: winuser.h:1591
static VOID SetBoldText(HWND hwndDlg, INT control, PSETUPDATA pSetupData)
Definition: setup.cpp:30
struct _NETWORKSETUPDATA * PNETWORKSETUPDATA
#define PSP_DEFAULT
Definition: prsht.h:22
#define BM_SETCHECK
Definition: winuser.h:1882
UINT uPostNetworkWizardPage
Definition: syssetup.h:73
static const WCHAR Title[]
Definition: oid.c:1259
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDS_NETWORKDOMAINSUBTITLE
Definition: resource.h:123
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PSWIZB_BACK
Definition: prsht.h:153
HINSTANCE hInstance
Definition: reactos.h:114
#define WINAPI
Definition: msvc.h:8
UINT uFirstNetworkWizardPage
Definition: syssetup.h:72
unsigned long DWORD
Definition: ntddk_ex.h:95
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDD_NETWORKSETTINGSPAGE
Definition: resource.h:55
#define IDS_NETWORKCOMPONENTSUBTITLE
Definition: resource.h:121
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define MB_ICONERROR
Definition: winuser.h:781
uint32_t DWORD_PTR
Definition: typedefs.h:63
#define IDC_NETWORK_TYPICAL
Definition: resource.h:56
HWND WINAPI GetParent(_In_ HWND)
#define IDD_NETWORKCOMPONENTPAGE
Definition: resource.h:59
#define IDS_WZD_DOMAIN_NAME
Definition: resource.h:125
static INT_PTR CALLBACK NetworkComponentPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: setup.cpp:126
HFONT hBoldFont
Definition: syssetup.h:51
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:807
unsigned int UINT
Definition: ndis.h:50
#define MB_OK
Definition: winuser.h:784
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
DWORD * PDWORD
Definition: pedump.c:68
#define IDC_DOMAIN_NAME
Definition: resource.h:69
#define BST_CHECKED
Definition: winuser.h:197
#define WM_SETFONT
Definition: winuser.h:1632
#define PSN_WIZBACK
Definition: prsht.h:120
DWORD WINAPI NetSetupRequestWizardPages(PDWORD pPageCount, HPROPSHEETPAGE *pPages, PSETUPDATA pSetupData)
Definition: setup.cpp:312
#define IDD_NETWORKDOMAINPAGE
Definition: resource.h:66
BOOL UnattendSetup
Definition: syssetup.h:60
PSETUPDATA pSetupData
Definition: setup.cpp:21
#define GetWindowLongPtr
Definition: treelist.c:73
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define HeapFree(x, y, z)
Definition: compat.h:394
#define PROPSHEETPAGE
Definition: prsht.h:371
#define WM_NOTIFY
Definition: richedit.h:61
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
static INT_PTR CALLBACK NetworkSettingsPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: setup.cpp:41