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