Reactos
1/*
2 * PROJECT: ReactOS System Control Panel Applet
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/sysdm/sysdm.c
5 * PURPOSE: dll entry file
6 * COPYRIGHT: Copyright Thomas Weidenmueller <w3seek@reactos.org>
7 *
8 */
9
10#include "precomp.h"
11
12#include <regstr.h>
13
14static LONG APIENTRY SystemApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
15HINSTANCE hApplet = 0;
16
17/* Applets */
18APPLET Applets[NUM_APPLETS] =
19{
20 {IDI_CPLSYSTEM, IDS_CPLSYSTEMNAME, IDS_CPLSYSTEMDESCRIPTION, SystemApplet}
21};
22
23#define MAX_SYSTEM_PAGES 32
24
25
26INT __cdecl
27ResourceMessageBox(
28 _In_opt_ HINSTANCE hInstance,
29 _In_opt_ HWND hwnd,
30 _In_ UINT uType,
31 _In_ UINT uCaption,
32 _In_ UINT uText,
33 ...)
34{
35 va_list args;
36 WCHAR szCaption[MAX_STR_LENGTH];
37 WCHAR szText[MAX_STR_LENGTH];
38 WCHAR szCookedText[2*MAX_STR_LENGTH];
39
40 LoadStringW(hInstance, uCaption, szCaption, _countof(szCaption));
41 LoadStringW(hInstance, uText, szText, _countof(szText));
42
43 va_start(args, uText);
44 StringCchVPrintfW(szCookedText, _countof(szCookedText),
45 szText, args);
46 va_end(args);
47
48 return MessageBoxW(hwnd,
49 szCookedText,
50 szCaption,
51 uType);
52}
53
54
55static BOOL CALLBACK
56PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
57{
58 PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
59 if (ppsh != NULL && ppsh->nPages < MAX_SYSTEM_PAGES)
60 {
61 ppsh->phpage[ppsh->nPages++] = hpage;
62 return TRUE;
63 }
64
65 return FALSE;
66}
67
68static BOOL
69InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc)
70{
71 HPROPSHEETPAGE hPage;
72 PROPSHEETPAGE psp;
73
74 if (ppsh->nPages < MAX_SYSTEM_PAGES)
75 {
76 ZeroMemory(&psp, sizeof(psp));
77 psp.dwSize = sizeof(psp);
78 psp.dwFlags = PSP_DEFAULT;
79 psp.hInstance = hApplet;
80 psp.pszTemplate = MAKEINTRESOURCE(idDlg);
81 psp.pfnDlgProc = DlgProc;
82
83 hPage = CreatePropertySheetPage(&psp);
84 if (hPage != NULL)
85 {
86 return PropSheetAddPage(hPage, (LPARAM)ppsh);
87 }
88 }
89
90 return FALSE;
91}
92
93typedef HPROPSHEETPAGE (WINAPI *PCreateNetIDPropertyPage)(VOID);
94
95static HMODULE
96AddNetIdPage(PROPSHEETHEADER *ppsh)
97{
98 HPROPSHEETPAGE hPage;
99 HMODULE hMod;
100 PCreateNetIDPropertyPage pCreateNetIdPage;
101
102 hMod = LoadLibrary(TEXT("netid.dll"));
103 if (hMod != NULL)
104 {
105 pCreateNetIdPage = (PCreateNetIDPropertyPage)GetProcAddress(hMod,
106 "CreateNetIDPropertyPage");
107 if (pCreateNetIdPage != NULL)
108 {
109 hPage = pCreateNetIdPage();
110 if (hPage == NULL)
111 goto Fail;
112
113 if (!PropSheetAddPage(hPage, (LPARAM)ppsh))
114 {
115 DestroyPropertySheetPage(hPage);
116 goto Fail;
117 }
118 }
119 else
120 {
121Fail:
122 FreeLibrary(hMod);
123 hMod = NULL;
124 }
125 }
126
127 return hMod;
128}
129
130static int CALLBACK
131PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
132{
133 // NOTE: This callback is needed to set large icon correctly.
134 HICON hIcon;
135 switch (uMsg)
136 {
137 case PSCB_INITIALIZED:
138 {
139 hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDI_CPLSYSTEM));
140 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
141 break;
142 }
143 }
144 return 0;
145}
146
147/* First Applet */
148LONG CALLBACK
149SystemApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
150{
151 HPROPSHEETPAGE hpsp[MAX_SYSTEM_PAGES];
152 PROPSHEETHEADER psh;
153 HMODULE hNetIdDll;
154 HPSXA hpsxa = NULL;
155 INT nPage = 0;
156 LONG Ret;
157 static INITCOMMONCONTROLSEX icc = {sizeof(INITCOMMONCONTROLSEX), ICC_LINK_CLASS};
158
159 if (!InitCommonControlsEx(&icc))
160 return 0;
161
162 if (uMsg == CPL_STARTWPARMSW && lParam != 0)
163 {
164 nPage = _wtoi((PWSTR)lParam);
165 }
166
167 if (nPage == -1)
168 {
169 ShowPerformanceOptions(hwnd);
170 return TRUE;
171 }
172
173 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
174 psh.dwSize = sizeof(PROPSHEETHEADER);
175 psh.dwFlags = PSH_PROPTITLE | PSH_USEICONID | PSH_USECALLBACK;
176 psh.hwndParent = hwnd;
177 psh.hInstance = hApplet;
178 psh.pszIcon = MAKEINTRESOURCEW(IDI_CPLSYSTEM);
179 psh.pszCaption = MAKEINTRESOURCE(IDS_CPLSYSTEMNAME);
180 psh.nPages = 0;
181 psh.nStartPage = 0;
182 psh.phpage = hpsp;
183 psh.pfnCallback = PropSheetProc;
184
185 InitPropSheetPage(&psh, IDD_PROPPAGEGENERAL, GeneralPageProc);
186 hNetIdDll = AddNetIdPage(&psh);
187 InitPropSheetPage(&psh, IDD_PROPPAGEHARDWARE, HardwarePageProc);
188 InitPropSheetPage(&psh, IDD_PROPPAGEADVANCED, AdvancedPageProc);
189
190 /* Load additional pages provided by shell extensions */
191 hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\System"), MAX_SYSTEM_PAGES - psh.nPages);
192 if (hpsxa != NULL)
193 {
194 SHAddFromPropSheetExtArray(hpsxa, PropSheetAddPage, (LPARAM)&psh);
195 }
196
197 if (nPage != 0 && nPage <= psh.nPages)
198 psh.nStartPage = nPage;
199
200 Ret = (LONG)(PropertySheet(&psh) != -1);
201
202 if (hpsxa != NULL)
203 {
204 SHDestroyPropSheetExtArray(hpsxa);
205 }
206
207 if (hNetIdDll != NULL)
208 FreeLibrary(hNetIdDll);
209
210 return Ret;
211}
212
213/* Control Panel Callback */
214LONG CALLBACK
215CPlApplet(HWND hwndCPl,
216 UINT uMsg,
217 LPARAM lParam1,
218 LPARAM lParam2)
219{
220 UINT i = (UINT)lParam1;
221
222 UNREFERENCED_PARAMETER(hwndCPl);
223
224 switch (uMsg)
225 {
226 case CPL_INIT:
227 return TRUE;
228
229 case CPL_GETCOUNT:
230 return NUM_APPLETS;
231
232 case CPL_INQUIRE:
233 if (i < NUM_APPLETS)
234 {
235 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
236 CPlInfo->lData = 0;
237 CPlInfo->idIcon = Applets[i].idIcon;
238 CPlInfo->idName = Applets[i].idName;
239 CPlInfo->idInfo = Applets[i].idDescription;
240 }
241 else
242 {
243 return TRUE;
244 }
245 break;
246
247 case CPL_DBLCLK:
248 if (i < NUM_APPLETS)
249 Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
250 else
251 return TRUE;
252 break;
253
254 case CPL_STARTWPARMSW:
255 if (i < NUM_APPLETS)
256 return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
257 break;
258 }
259
260 return FALSE;
261}
262
263
264BOOL WINAPI
265DllMain(HINSTANCE hinstDLL,
266 DWORD dwReason,
267 LPVOID lpvReserved)
268{
269 UNREFERENCED_PARAMETER(lpvReserved);
270
271 switch (dwReason)
272 {
273 case DLL_PROCESS_ATTACH:
274 case DLL_THREAD_ATTACH:
275 hApplet = hinstDLL;
276 break;
277 }
278
279 return TRUE;
280}