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 /* First Applet */ 125 LONG CALLBACK 126 SystemApplet(VOID) 127 { 128 HPROPSHEETPAGE hpsp[MAX_SYSTEM_PAGES]; 129 PROPSHEETHEADER psh; 130 HMODULE hNetIdDll; 131 HPSXA hpsxa = NULL; 132 LONG Ret; 133 static INITCOMMONCONTROLSEX icc = {sizeof(INITCOMMONCONTROLSEX), ICC_LINK_CLASS}; 134 135 if (!InitCommonControlsEx(&icc)) 136 return 0; 137 138 ZeroMemory(&psh, sizeof(PROPSHEETHEADER)); 139 psh.dwSize = sizeof(PROPSHEETHEADER); 140 psh.dwFlags = PSH_PROPTITLE; 141 psh.hwndParent = hCPLWindow; 142 psh.hInstance = hApplet; 143 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM)); 144 psh.pszCaption = MAKEINTRESOURCE(IDS_CPLSYSTEMNAME); 145 psh.nPages = 0; 146 psh.nStartPage = 0; 147 psh.phpage = hpsp; 148 psh.pfnCallback = NULL; 149 150 InitPropSheetPage(&psh, IDD_PROPPAGEGENERAL, (DLGPROC) GeneralPageProc); 151 hNetIdDll = AddNetIdPage(&psh); 152 InitPropSheetPage(&psh, IDD_PROPPAGEHARDWARE, (DLGPROC) HardwarePageProc); 153 InitPropSheetPage(&psh, IDD_PROPPAGEADVANCED, (DLGPROC) AdvancedPageProc); 154 155 /* Load additional pages provided by shell extensions */ 156 hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\System"), MAX_SYSTEM_PAGES - psh.nPages); 157 if (hpsxa != NULL) 158 { 159 SHAddFromPropSheetExtArray(hpsxa, PropSheetAddPage, (LPARAM)&psh); 160 } 161 162 Ret = (LONG)(PropertySheet(&psh) != -1); 163 164 if (hpsxa != NULL) 165 { 166 SHDestroyPropSheetExtArray(hpsxa); 167 } 168 169 if (hNetIdDll != NULL) 170 FreeLibrary(hNetIdDll); 171 172 return Ret; 173 } 174 175 /* Control Panel Callback */ 176 LONG CALLBACK 177 CPlApplet(HWND hwndCPl, 178 UINT uMsg, 179 LPARAM lParam1, 180 LPARAM lParam2) 181 { 182 INT i = (INT)lParam1; 183 184 UNREFERENCED_PARAMETER(hwndCPl); 185 186 switch (uMsg) 187 { 188 case CPL_INIT: 189 return TRUE; 190 191 case CPL_GETCOUNT: 192 return NUM_APPLETS; 193 194 case CPL_INQUIRE: 195 { 196 CPLINFO *CPlInfo = (CPLINFO*)lParam2; 197 CPlInfo->lData = 0; 198 CPlInfo->idIcon = Applets[i].idIcon; 199 CPlInfo->idName = Applets[i].idName; 200 CPlInfo->idInfo = Applets[i].idDescription; 201 } 202 break; 203 204 case CPL_DBLCLK: 205 hCPLWindow = hwndCPl; 206 Applets[i].AppletProc(); 207 break; 208 } 209 210 return FALSE; 211 } 212 213 214 BOOL WINAPI 215 DllMain(HINSTANCE hinstDLL, 216 DWORD dwReason, 217 LPVOID lpvReserved) 218 { 219 UNREFERENCED_PARAMETER(lpvReserved); 220 221 switch (dwReason) 222 { 223 case DLL_PROCESS_ATTACH: 224 case DLL_THREAD_ATTACH: 225 hApplet = hinstDLL; 226 break; 227 } 228 229 return TRUE; 230 } 231