xref: /reactos/dll/shellext/netshell/setup.cpp (revision 78f13ae5)
18d47872eSGiannis Adamopoulos /*
28d47872eSGiannis Adamopoulos  * PROJECT:     ReactOS Shell
38d47872eSGiannis Adamopoulos  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
48d47872eSGiannis Adamopoulos  * PURPOSE:     ReactOS Networking Configuration
58d47872eSGiannis Adamopoulos  * COPYRIGHT:   Copyright 2016 Eric Kohl
68d47872eSGiannis Adamopoulos  */
78d47872eSGiannis Adamopoulos 
8c2c66affSColin Finck #include "precomp.h"
9c2c66affSColin Finck 
10c2c66affSColin Finck #include <syssetup/syssetup.h>
11c2c66affSColin Finck 
12c2c66affSColin Finck 
13c2c66affSColin Finck #define NETWORK_SETUP_MAGIC 0x50515253
14c2c66affSColin Finck 
15c2c66affSColin Finck typedef struct _NETWORKSETUPDATA
16c2c66affSColin Finck {
17c2c66affSColin Finck     DWORD dwMagic;
18c2c66affSColin Finck     BOOL bTypicalNetworkSetup;
19c2c66affSColin Finck 
20c2c66affSColin Finck 
21c2c66affSColin Finck     PSETUPDATA pSetupData;
22c2c66affSColin Finck } NETWORKSETUPDATA, *PNETWORKSETUPDATA;
23c2c66affSColin Finck 
24c2c66affSColin Finck 
25c2c66affSColin Finck extern "C"
26c2c66affSColin Finck {
27c2c66affSColin Finck 
28c2c66affSColin Finck static
29c2c66affSColin Finck VOID
SetBoldText(HWND hwndDlg,INT control,PSETUPDATA pSetupData)30c2c66affSColin Finck SetBoldText(
31c2c66affSColin Finck     HWND hwndDlg,
32c2c66affSColin Finck     INT control,
33c2c66affSColin Finck     PSETUPDATA pSetupData)
34c2c66affSColin Finck {
35c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, control, WM_SETFONT, (WPARAM)pSetupData->hBoldFont, MAKELPARAM(TRUE, 0));
36c2c66affSColin Finck }
37c2c66affSColin Finck 
38*78f13ae5SEric Kohl 
39*78f13ae5SEric Kohl static
40*78f13ae5SEric Kohl HRESULT
InstallTypicalNetworkSettings(VOID)41*78f13ae5SEric Kohl InstallTypicalNetworkSettings(VOID)
42*78f13ae5SEric Kohl {
43*78f13ae5SEric Kohl     INetCfg *pNetCfg = NULL;
44*78f13ae5SEric Kohl     INetCfgLock *pNetCfgLock = NULL;
45*78f13ae5SEric Kohl     INetCfgComponent *pTcpipComponent = NULL;
46*78f13ae5SEric Kohl     INetCfgComponent *pNicComponent = NULL;
47*78f13ae5SEric Kohl     IEnumNetCfgComponent *pEnumNicComponents = NULL;
48*78f13ae5SEric Kohl     WCHAR *pszNicName;
49*78f13ae5SEric Kohl     BOOL fWriteLocked = FALSE, fInitialized = FALSE;
50*78f13ae5SEric Kohl     HRESULT hr;
51*78f13ae5SEric Kohl 
52*78f13ae5SEric Kohl     TRACE("InstallTypicalNetworkSettings()\n");
53*78f13ae5SEric Kohl 
54*78f13ae5SEric Kohl     hr = CoInitialize(NULL);
55*78f13ae5SEric Kohl     if (hr != S_OK)
56*78f13ae5SEric Kohl     {
57*78f13ae5SEric Kohl         ERR("CoInitialize failed\n");
58*78f13ae5SEric Kohl         goto exit;
59*78f13ae5SEric Kohl     }
60*78f13ae5SEric Kohl 
61*78f13ae5SEric Kohl     hr = CoCreateInstance(CLSID_CNetCfg,
62*78f13ae5SEric Kohl                           NULL,
63*78f13ae5SEric Kohl                           CLSCTX_INPROC_SERVER,
64*78f13ae5SEric Kohl                           IID_INetCfg,
65*78f13ae5SEric Kohl                           (PVOID*)&pNetCfg);
66*78f13ae5SEric Kohl     if (hr != S_OK)
67*78f13ae5SEric Kohl     {
68*78f13ae5SEric Kohl         ERR("CoCreateInstance failed\n");
69*78f13ae5SEric Kohl         goto exit;
70*78f13ae5SEric Kohl     }
71*78f13ae5SEric Kohl 
72*78f13ae5SEric Kohl     /* Acquire the write-lock */
73*78f13ae5SEric Kohl     hr = pNetCfg->QueryInterface(IID_INetCfgLock,
74*78f13ae5SEric Kohl                                  (PVOID*)&pNetCfgLock);
75*78f13ae5SEric Kohl     if (hr != S_OK)
76*78f13ae5SEric Kohl     {
77*78f13ae5SEric Kohl         ERR("QueryInterface failed\n");
78*78f13ae5SEric Kohl         goto exit;
79*78f13ae5SEric Kohl     }
80*78f13ae5SEric Kohl 
81*78f13ae5SEric Kohl     hr = pNetCfgLock->AcquireWriteLock(5000,
82*78f13ae5SEric Kohl                                        L"SysSetup",
83*78f13ae5SEric Kohl                                        NULL);
84*78f13ae5SEric Kohl     if (hr != S_OK)
85*78f13ae5SEric Kohl     {
86*78f13ae5SEric Kohl         ERR("AcquireWriteLock failed\n");
87*78f13ae5SEric Kohl         goto exit;
88*78f13ae5SEric Kohl     }
89*78f13ae5SEric Kohl 
90*78f13ae5SEric Kohl     fWriteLocked = TRUE;
91*78f13ae5SEric Kohl 
92*78f13ae5SEric Kohl     /* Initialize the network configuration */
93*78f13ae5SEric Kohl     hr = pNetCfg->Initialize(NULL);
94*78f13ae5SEric Kohl     if (hr != S_OK)
95*78f13ae5SEric Kohl     {
96*78f13ae5SEric Kohl         ERR("Initialize failed\n");
97*78f13ae5SEric Kohl         goto exit;
98*78f13ae5SEric Kohl     }
99*78f13ae5SEric Kohl 
100*78f13ae5SEric Kohl     fInitialized = TRUE;
101*78f13ae5SEric Kohl 
102*78f13ae5SEric Kohl     /* Find the TCP/IP driver */
103*78f13ae5SEric Kohl     hr = pNetCfg->FindComponent(L"ms_tcpip",
104*78f13ae5SEric Kohl                                 &pTcpipComponent);
105*78f13ae5SEric Kohl     if (hr == S_OK)
106*78f13ae5SEric Kohl     {
107*78f13ae5SEric Kohl         FIXME("Found the TCP/IP driver!\n");
108*78f13ae5SEric Kohl     }
109*78f13ae5SEric Kohl     else
110*78f13ae5SEric Kohl     {
111*78f13ae5SEric Kohl         ERR("Initialize failed\n");
112*78f13ae5SEric Kohl         goto exit;
113*78f13ae5SEric Kohl     }
114*78f13ae5SEric Kohl 
115*78f13ae5SEric Kohl     hr = pNetCfg->EnumComponents(&GUID_DEVCLASS_NET,
116*78f13ae5SEric Kohl                                  &pEnumNicComponents);
117*78f13ae5SEric Kohl     if (hr != S_OK)
118*78f13ae5SEric Kohl     {
119*78f13ae5SEric Kohl         ERR("EnumComponents failed\n");
120*78f13ae5SEric Kohl         goto exit;
121*78f13ae5SEric Kohl     }
122*78f13ae5SEric Kohl 
123*78f13ae5SEric Kohl     for (;;)
124*78f13ae5SEric Kohl     {
125*78f13ae5SEric Kohl         hr = pEnumNicComponents->Next(1,
126*78f13ae5SEric Kohl                                       &pNicComponent,
127*78f13ae5SEric Kohl                                       NULL);
128*78f13ae5SEric Kohl         if (hr != S_OK)
129*78f13ae5SEric Kohl         {
130*78f13ae5SEric Kohl             TRACE("EnumNicComponents done!\n");
131*78f13ae5SEric Kohl             break;
132*78f13ae5SEric Kohl         }
133*78f13ae5SEric Kohl 
134*78f13ae5SEric Kohl         hr = pNicComponent->GetDisplayName(&pszNicName);
135*78f13ae5SEric Kohl         if (hr == S_OK)
136*78f13ae5SEric Kohl         {
137*78f13ae5SEric Kohl             FIXME("NIC name: %S\n", pszNicName);
138*78f13ae5SEric Kohl             CoTaskMemFree(pszNicName);
139*78f13ae5SEric Kohl         }
140*78f13ae5SEric Kohl 
141*78f13ae5SEric Kohl         // FIXME Bind Tcpip to the NIC
142*78f13ae5SEric Kohl 
143*78f13ae5SEric Kohl         pNicComponent->Release();
144*78f13ae5SEric Kohl         pNicComponent = NULL;
145*78f13ae5SEric Kohl     }
146*78f13ae5SEric Kohl 
147*78f13ae5SEric Kohl     TRACE("Done!\n");
148*78f13ae5SEric Kohl exit:
149*78f13ae5SEric Kohl     if (pNicComponent != NULL)
150*78f13ae5SEric Kohl         pNicComponent->Release();
151*78f13ae5SEric Kohl 
152*78f13ae5SEric Kohl     if (pEnumNicComponents != NULL)
153*78f13ae5SEric Kohl         pEnumNicComponents->Release();
154*78f13ae5SEric Kohl 
155*78f13ae5SEric Kohl     if (pTcpipComponent != NULL)
156*78f13ae5SEric Kohl         pTcpipComponent->Release();
157*78f13ae5SEric Kohl 
158*78f13ae5SEric Kohl     if (fInitialized)
159*78f13ae5SEric Kohl         pNetCfg->Uninitialize();
160*78f13ae5SEric Kohl 
161*78f13ae5SEric Kohl     if (fWriteLocked)
162*78f13ae5SEric Kohl         pNetCfgLock->ReleaseWriteLock();
163*78f13ae5SEric Kohl 
164*78f13ae5SEric Kohl     if (pNetCfgLock != NULL)
165*78f13ae5SEric Kohl         pNetCfgLock->Release();
166*78f13ae5SEric Kohl 
167*78f13ae5SEric Kohl     if (pNetCfg != NULL)
168*78f13ae5SEric Kohl         pNetCfg->Release();
169*78f13ae5SEric Kohl 
170*78f13ae5SEric Kohl     CoUninitialize();
171*78f13ae5SEric Kohl 
172*78f13ae5SEric Kohl     TRACE("InstallTypicalNetworkSettings() done!\n");
173*78f13ae5SEric Kohl 
174*78f13ae5SEric Kohl     return hr;
175*78f13ae5SEric Kohl }
176*78f13ae5SEric Kohl 
177*78f13ae5SEric Kohl 
178c2c66affSColin Finck static
179c2c66affSColin Finck INT_PTR
180c2c66affSColin Finck CALLBACK
NetworkSettingsPageDlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)181c2c66affSColin Finck NetworkSettingsPageDlgProc(
182c2c66affSColin Finck     HWND hwndDlg,
183c2c66affSColin Finck     UINT uMsg,
184c2c66affSColin Finck     WPARAM wParam,
185c2c66affSColin Finck     LPARAM lParam)
186c2c66affSColin Finck {
187c2c66affSColin Finck     PNETWORKSETUPDATA pNetworkSetupData;
188c2c66affSColin Finck     PSETUPDATA pSetupData;
189c2c66affSColin Finck     LPNMHDR lpnm;
190c2c66affSColin Finck 
191c2c66affSColin Finck     /* Retrieve pointer to the global setup data */
192d281d14fSTimo Kreuzer     pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
193c2c66affSColin Finck     if ((pNetworkSetupData != NULL) &&
194c2c66affSColin Finck         (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
195c2c66affSColin Finck         pSetupData = pNetworkSetupData->pSetupData;
196c2c66affSColin Finck 
197c2c66affSColin Finck     switch (uMsg)
198c2c66affSColin Finck     {
199c2c66affSColin Finck         case WM_INITDIALOG:
200c2c66affSColin Finck             /* Save pointer to the global setup data */
201c2c66affSColin Finck             pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
202d281d14fSTimo Kreuzer             SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
203c2c66affSColin Finck             pSetupData = pNetworkSetupData->pSetupData;
204c2c66affSColin Finck 
205c2c66affSColin Finck             /* Set the fonts of both the options to bold */
206c2c66affSColin Finck             SetBoldText(hwndDlg, IDC_NETWORK_TYPICAL, pSetupData);
207c2c66affSColin Finck             SetBoldText(hwndDlg, IDC_NETWORK_CUSTOM, pSetupData);
208c2c66affSColin Finck 
209c2c66affSColin Finck             /* Set the typical settings option as the default */
210c2c66affSColin Finck             SendDlgItemMessage(hwndDlg, IDC_NETWORK_TYPICAL, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
211c2c66affSColin Finck 
212c2c66affSColin Finck             if (pSetupData->UnattendSetup)
213c2c66affSColin Finck             {
214c2c66affSColin Finck                 //...
215c2c66affSColin Finck             }
216c2c66affSColin Finck             break;
217c2c66affSColin Finck 
218c2c66affSColin Finck         case WM_DESTROY:
219c2c66affSColin Finck             /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
220c2c66affSColin Finck             //...
221c2c66affSColin Finck             break;
222c2c66affSColin Finck 
223c2c66affSColin Finck         case WM_NOTIFY:
224c2c66affSColin Finck             lpnm = (LPNMHDR)lParam;
225c2c66affSColin Finck 
226c2c66affSColin Finck             switch (lpnm->code)
227c2c66affSColin Finck             {
228c2c66affSColin Finck                 case PSN_SETACTIVE:
229c2c66affSColin Finck                     /* Enable the Back and Next buttons */
230c2c66affSColin Finck                     PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
231c2c66affSColin Finck                     if (pSetupData->UnattendSetup)
232c2c66affSColin Finck                     {
2330182dcd7STimo Kreuzer                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKCOMPONENTPAGE);
234c2c66affSColin Finck                         return TRUE;
235c2c66affSColin Finck                     }
236c2c66affSColin Finck                     break;
237c2c66affSColin Finck 
238c2c66affSColin Finck                 case PSN_WIZNEXT:
239c2c66affSColin Finck                     pNetworkSetupData->bTypicalNetworkSetup = FALSE;
240c2c66affSColin Finck 
241c2c66affSColin Finck                     /* If the Typical Settings button is chosen, then skip to the Domain Page */
242c2c66affSColin Finck                     if (IsDlgButtonChecked(hwndDlg, IDC_NETWORK_TYPICAL) == BST_CHECKED)
243c2c66affSColin Finck                     {
244c2c66affSColin Finck                         pNetworkSetupData->bTypicalNetworkSetup = TRUE;
245*78f13ae5SEric Kohl 
246*78f13ae5SEric Kohl                         InstallTypicalNetworkSettings();
247*78f13ae5SEric Kohl 
2480182dcd7STimo Kreuzer                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKDOMAINPAGE);
249c2c66affSColin Finck                         return TRUE;
250c2c66affSColin Finck                     }
251c2c66affSColin Finck                     break;
252c2c66affSColin Finck 
253c2c66affSColin Finck                 case PSN_WIZBACK:
254c2c66affSColin Finck                     pSetupData->UnattendSetup = FALSE;
255c2c66affSColin Finck                     break;
256c2c66affSColin Finck             }
257c2c66affSColin Finck             break;
258c2c66affSColin Finck 
259c2c66affSColin Finck         default:
260c2c66affSColin Finck             break;
261c2c66affSColin Finck     }
262c2c66affSColin Finck 
263c2c66affSColin Finck     return FALSE;
264c2c66affSColin Finck }
265c2c66affSColin Finck 
266c2c66affSColin Finck static
267c2c66affSColin Finck INT_PTR
268c2c66affSColin Finck CALLBACK
NetworkComponentPageDlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)269c2c66affSColin Finck NetworkComponentPageDlgProc(
270c2c66affSColin Finck     HWND hwndDlg,
271c2c66affSColin Finck     UINT uMsg,
272c2c66affSColin Finck     WPARAM wParam,
273c2c66affSColin Finck     LPARAM lParam)
274c2c66affSColin Finck {
275c2c66affSColin Finck     PNETWORKSETUPDATA pNetworkSetupData;
276c2c66affSColin Finck     PSETUPDATA pSetupData;
277c2c66affSColin Finck     LPNMHDR lpnm;
278c2c66affSColin Finck 
279c2c66affSColin Finck     /* Retrieve pointer to the global setup data */
280d281d14fSTimo Kreuzer     pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
281c2c66affSColin Finck     if ((pNetworkSetupData != NULL) &&
282c2c66affSColin Finck         (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
283c2c66affSColin Finck         pSetupData = pNetworkSetupData->pSetupData;
284c2c66affSColin Finck 
285c2c66affSColin Finck     switch (uMsg)
286c2c66affSColin Finck     {
287c2c66affSColin Finck         case WM_INITDIALOG:
288c2c66affSColin Finck             /* Save pointer to the global setup data */
289c2c66affSColin Finck             pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
290d281d14fSTimo Kreuzer             SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
291c2c66affSColin Finck             pSetupData = pNetworkSetupData->pSetupData;
292c2c66affSColin Finck 
293c2c66affSColin Finck             SetBoldText(hwndDlg, IDC_NETWORK_DEVICE, pSetupData);
294c2c66affSColin Finck 
295c2c66affSColin Finck             if (pSetupData->UnattendSetup)
296c2c66affSColin Finck             {
297c2c66affSColin Finck                 //...
298c2c66affSColin Finck             }
299c2c66affSColin Finck             break;
300c2c66affSColin Finck 
301c2c66affSColin Finck         case WM_DESTROY:
302c2c66affSColin Finck             /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
303c2c66affSColin Finck             //...
304c2c66affSColin Finck             break;
305c2c66affSColin Finck 
306c2c66affSColin Finck         case WM_NOTIFY:
307c2c66affSColin Finck             lpnm = (LPNMHDR)lParam;
308c2c66affSColin Finck 
309c2c66affSColin Finck             switch (lpnm->code)
310c2c66affSColin Finck             {
311c2c66affSColin Finck                 case PSN_SETACTIVE:
312c2c66affSColin Finck                     /* Enable the Back and Next buttons */
313c2c66affSColin Finck                     PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
314c2c66affSColin Finck                     if (pSetupData->UnattendSetup)
315c2c66affSColin Finck                     {
3160182dcd7STimo Kreuzer                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKDOMAINPAGE);
317c2c66affSColin Finck                         return TRUE;
318c2c66affSColin Finck                     }
319c2c66affSColin Finck                     break;
320c2c66affSColin Finck 
321c2c66affSColin Finck                 case PSN_WIZBACK:
322c2c66affSColin Finck                     pSetupData->UnattendSetup = FALSE;
323c2c66affSColin Finck                     break;
324c2c66affSColin Finck             }
325c2c66affSColin Finck             break;
326c2c66affSColin Finck 
327c2c66affSColin Finck         default:
328c2c66affSColin Finck             break;
329c2c66affSColin Finck     }
330c2c66affSColin Finck 
331c2c66affSColin Finck     return FALSE;
332c2c66affSColin Finck }
333c2c66affSColin Finck 
334c2c66affSColin Finck static
335c2c66affSColin Finck INT_PTR
336c2c66affSColin Finck CALLBACK
NetworkDomainPageDlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)337c2c66affSColin Finck NetworkDomainPageDlgProc(
338c2c66affSColin Finck     HWND hwndDlg,
339c2c66affSColin Finck     UINT uMsg,
340c2c66affSColin Finck     WPARAM wParam,
341c2c66affSColin Finck     LPARAM lParam)
342c2c66affSColin Finck {
343c2c66affSColin Finck     PNETWORKSETUPDATA pNetworkSetupData;
344c2c66affSColin Finck     PSETUPDATA pSetupData;
345c2c66affSColin Finck     WCHAR DomainName[51];
346c2c66affSColin Finck     WCHAR Title[64];
347c2c66affSColin Finck     WCHAR ErrorName[256];
348c2c66affSColin Finck     LPNMHDR lpnm;
349c2c66affSColin Finck 
350c2c66affSColin Finck     /* Retrieve pointer to the global setup data */
351d281d14fSTimo Kreuzer     pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
352c2c66affSColin Finck     if ((pNetworkSetupData != NULL) &&
353c2c66affSColin Finck         (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
354c2c66affSColin Finck         pSetupData = pNetworkSetupData->pSetupData;
355c2c66affSColin Finck 
356c2c66affSColin Finck     switch (uMsg)
357c2c66affSColin Finck     {
358c2c66affSColin Finck         case WM_INITDIALOG:
359c2c66affSColin Finck             /* Save pointer to the global setup data */
360c2c66affSColin Finck             pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
361d281d14fSTimo Kreuzer             SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
362c2c66affSColin Finck             pSetupData = pNetworkSetupData->pSetupData;
363c2c66affSColin Finck 
364c2c66affSColin Finck             /* Set the workgroup option as the default */
365c2c66affSColin Finck             SendDlgItemMessage(hwndDlg, IDC_SELECT_WORKGROUP, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
366c2c66affSColin Finck 
367c2c66affSColin Finck             wcscpy(DomainName, L"WORKGROUP");
368c2c66affSColin Finck 
369c2c66affSColin Finck             /* Display current computer name */
370c2c66affSColin Finck             SetDlgItemTextW(hwndDlg, IDC_DOMAIN_NAME, DomainName);
371c2c66affSColin Finck 
372c2c66affSColin Finck             /* Set focus to owner name */
373c2c66affSColin Finck             SetFocus(GetDlgItem(hwndDlg, IDC_DOMAIN_NAME));
374c2c66affSColin Finck 
375c2c66affSColin Finck             if (pSetupData->UnattendSetup)
376c2c66affSColin Finck             {
377c2c66affSColin Finck                 //...
378c2c66affSColin Finck             }
379c2c66affSColin Finck             break;
380c2c66affSColin Finck 
381c2c66affSColin Finck         case WM_DESTROY:
382c2c66affSColin Finck             //...
383c2c66affSColin Finck             /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
384c2c66affSColin Finck             if (pNetworkSetupData != NULL)
385c2c66affSColin Finck             {
386c2c66affSColin Finck                 if ((!IsBadReadPtr(pNetworkSetupData, sizeof(NETWORKSETUPDATA))) &&
387c2c66affSColin Finck                     (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
388c2c66affSColin Finck                     HeapFree(GetProcessHeap(), 0, pNetworkSetupData);
389c2c66affSColin Finck 
390d281d14fSTimo Kreuzer                 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)NULL);
391c2c66affSColin Finck             }
392c2c66affSColin Finck             break;
393c2c66affSColin Finck 
394c2c66affSColin Finck         case WM_NOTIFY:
395c2c66affSColin Finck             lpnm = (LPNMHDR)lParam;
396c2c66affSColin Finck 
397c2c66affSColin Finck             switch (lpnm->code)
398c2c66affSColin Finck             {
399c2c66affSColin Finck                 case PSN_SETACTIVE:
400c2c66affSColin Finck                     /* Enable the Back and Next buttons */
401c2c66affSColin Finck                     PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
402c2c66affSColin Finck                     if (pSetupData->UnattendSetup)
403c2c66affSColin Finck                     {
4040182dcd7STimo Kreuzer                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, pSetupData->uPostNetworkWizardPage);
405c2c66affSColin Finck                         return TRUE;
406c2c66affSColin Finck                     }
407c2c66affSColin Finck                     break;
408c2c66affSColin Finck 
409c2c66affSColin Finck                 case PSN_WIZNEXT:
410c2c66affSColin Finck                     DomainName[0] = 0;
411c2c66affSColin Finck                     if (GetDlgItemTextW(hwndDlg, IDC_DOMAIN_NAME, DomainName, 50) == 0)
412c2c66affSColin Finck                     {
413c2c66affSColin Finck                         if (0 == LoadStringW(netshell_hInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
414c2c66affSColin Finck                         {
415c2c66affSColin Finck                             wcscpy(Title, L"ReactOS Setup");
416c2c66affSColin Finck                         }
417c2c66affSColin Finck                         if (0 == LoadStringW(netshell_hInstance, IDS_WZD_DOMAIN_NAME, ErrorName, sizeof(ErrorName) / sizeof(ErrorName[0])))
418c2c66affSColin Finck                         {
419c2c66affSColin Finck                             wcscpy(ErrorName, L"Setup cannot continue until you\nenter the name of your domain/workgroup.");
420c2c66affSColin Finck                         }
421c2c66affSColin Finck                         MessageBoxW(hwndDlg, ErrorName, Title, MB_ICONERROR | MB_OK);
422c2c66affSColin Finck 
423c2c66affSColin Finck                         SetFocus(GetDlgItem(hwndDlg, IDC_DOMAIN_NAME));
4240182dcd7STimo Kreuzer                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
425c2c66affSColin Finck 
426c2c66affSColin Finck                         //TODO: Implement setting the Domain/Workgroup
427c2c66affSColin Finck 
428c2c66affSColin Finck                         return TRUE;
429c2c66affSColin Finck                     }
430c2c66affSColin Finck                     break;
431c2c66affSColin Finck 
432c2c66affSColin Finck                 case PSN_WIZBACK:
433c2c66affSColin Finck                     pSetupData->UnattendSetup = FALSE;
434c2c66affSColin Finck 
435c2c66affSColin Finck                     /* If the Typical setup chosen, then skip back to the Settings Page */
436c2c66affSColin Finck                     if (pNetworkSetupData->bTypicalNetworkSetup == TRUE)
437c2c66affSColin Finck                     {
4380182dcd7STimo Kreuzer                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKSETTINGSPAGE);
439c2c66affSColin Finck                         return TRUE;
440c2c66affSColin Finck                     }
441c2c66affSColin Finck                     break;
442c2c66affSColin Finck             }
443c2c66affSColin Finck             break;
444c2c66affSColin Finck 
445c2c66affSColin Finck         default:
446c2c66affSColin Finck             break;
447c2c66affSColin Finck     }
448c2c66affSColin Finck 
449c2c66affSColin Finck     return FALSE;
450c2c66affSColin Finck }
451c2c66affSColin Finck 
452c2c66affSColin Finck 
453c2c66affSColin Finck DWORD
454c2c66affSColin Finck WINAPI
NetSetupRequestWizardPages(PDWORD pPageCount,HPROPSHEETPAGE * pPages,PSETUPDATA pSetupData)455c2c66affSColin Finck NetSetupRequestWizardPages(
456c2c66affSColin Finck     PDWORD pPageCount,
457c2c66affSColin Finck     HPROPSHEETPAGE *pPages,
458c2c66affSColin Finck     PSETUPDATA pSetupData)
459c2c66affSColin Finck {
460c2c66affSColin Finck     PNETWORKSETUPDATA pNetworkSetupData;
461c2c66affSColin Finck     PROPSHEETPAGE psp = {0};
462c2c66affSColin Finck     DWORD dwPageCount = 3;
463c2c66affSColin Finck     INT nPage = 0;
464c2c66affSColin Finck 
465c2c66affSColin Finck     if (pPageCount == NULL)
466c2c66affSColin Finck         return ERROR_INVALID_PARAMETER;
467c2c66affSColin Finck 
468c2c66affSColin Finck     if (pPages == NULL)
469c2c66affSColin Finck     {
470c2c66affSColin Finck         *pPageCount = dwPageCount;
471c2c66affSColin Finck         return ERROR_SUCCESS;
472c2c66affSColin Finck     }
473c2c66affSColin Finck 
474c2c66affSColin Finck     if (*pPageCount < dwPageCount)
475c2c66affSColin Finck         return ERROR_BUFFER_OVERFLOW;
476c2c66affSColin Finck 
477c2c66affSColin Finck     pSetupData->uFirstNetworkWizardPage = IDD_NETWORKSETTINGSPAGE;
478c2c66affSColin Finck 
479c2c66affSColin Finck     pNetworkSetupData = (PNETWORKSETUPDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(NETWORKSETUPDATA));
480c2c66affSColin Finck     if (pNetworkSetupData == NULL)
481c2c66affSColin Finck         return ERROR_OUTOFMEMORY;
482c2c66affSColin Finck 
483c2c66affSColin Finck     pNetworkSetupData->dwMagic = NETWORK_SETUP_MAGIC;
484c2c66affSColin Finck     pNetworkSetupData->pSetupData = pSetupData;
485c2c66affSColin Finck 
486c2c66affSColin Finck 
487c2c66affSColin Finck     /* Create the Network Settings page */
488c2c66affSColin Finck     psp.dwSize = sizeof(PROPSHEETPAGE);
489c2c66affSColin Finck     psp.hInstance = netshell_hInstance;
490c2c66affSColin Finck     psp.lParam = (LPARAM)pNetworkSetupData;
491c2c66affSColin Finck 
492c2c66affSColin Finck     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
493c2c66affSColin Finck     psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKSETTINGSTITLE);
494c2c66affSColin Finck     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKSETTINGSSUBTITLE);
495c2c66affSColin Finck     psp.pfnDlgProc = NetworkSettingsPageDlgProc;
496c2c66affSColin Finck     psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKSETTINGSPAGE);
497c2c66affSColin Finck     pPages[nPage++] = CreatePropertySheetPage(&psp);
498c2c66affSColin Finck 
499c2c66affSColin Finck     /* Create the Network Components page */
500c2c66affSColin Finck     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
501c2c66affSColin Finck     psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKCOMPONENTTITLE);
502c2c66affSColin Finck     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKCOMPONENTSUBTITLE);
503c2c66affSColin Finck     psp.pfnDlgProc = NetworkComponentPageDlgProc;
504c2c66affSColin Finck     psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKCOMPONENTPAGE);
505c2c66affSColin Finck     pPages[nPage++] = CreatePropertySheetPage(&psp);
506c2c66affSColin Finck 
507c2c66affSColin Finck     /* Create the Domain/Workgroup page */
508c2c66affSColin Finck     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
509c2c66affSColin Finck     psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKDOMAINTITLE);
510c2c66affSColin Finck     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKDOMAINSUBTITLE);
511c2c66affSColin Finck     psp.pfnDlgProc = NetworkDomainPageDlgProc;
512c2c66affSColin Finck     psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKDOMAINPAGE);
513c2c66affSColin Finck     pPages[nPage++] = CreatePropertySheetPage(&psp);
514c2c66affSColin Finck 
515c2c66affSColin Finck     *pPageCount = dwPageCount;
516c2c66affSColin Finck 
517c2c66affSColin Finck     return ERROR_SUCCESS;
518c2c66affSColin Finck }
519c2c66affSColin Finck 
520c2c66affSColin Finck } // extern "C"
521