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