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