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