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