1 /* 2 * PROJECT: ReactOS Power Configuration Applet 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: dll/cpl/powercfg/powercfg.c 5 * PURPOSE: initialization of applet 6 * PROGRAMMERS: Alexander Wurzinger (Lohnegrim at gmx dot net) 7 * Johannes Anderwald (johannes.anderwald@reactos.org) 8 * Martin Rottensteiner 9 * Dmitry Chapyshev (lentind@yandex.ru) 10 */ 11 12 #include "powercfg.h" 13 14 #include <winreg.h> 15 #include <regstr.h> 16 17 #define NUM_APPLETS (1) 18 19 static LONG APIENTRY Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam); 20 21 22 HINSTANCE hApplet = 0; 23 GLOBAL_POWER_POLICY gGPP; 24 TCHAR langSel[255]; 25 26 /* Applets */ 27 APPLET Applets[NUM_APPLETS] = 28 { 29 {IDC_CPLICON_1, IDS_CPLNAME_1, IDS_CPLDESCRIPTION_1, Applet1} 30 }; 31 32 static BOOL CALLBACK 33 PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam) 34 { 35 PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam; 36 if (ppsh != NULL && ppsh->nPages < MAX_POWER_PAGES) 37 { 38 ppsh->phpage[ppsh->nPages++] = hpage; 39 return TRUE; 40 } 41 42 return FALSE; 43 } 44 45 static BOOL 46 InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc) 47 { 48 HPROPSHEETPAGE hPage; 49 PROPSHEETPAGE psp; 50 51 if (ppsh->nPages < MAX_POWER_PAGES) 52 { 53 ZeroMemory(&psp, sizeof(psp)); 54 psp.dwSize = sizeof(psp); 55 psp.dwFlags = PSP_DEFAULT; 56 psp.hInstance = hApplet; 57 psp.pszTemplate = MAKEINTRESOURCE(idDlg); 58 psp.pfnDlgProc = DlgProc; 59 60 hPage = CreatePropertySheetPage(&psp); 61 if (hPage != NULL) 62 { 63 return PropSheetAddPage(hPage, (LPARAM)ppsh); 64 } 65 } 66 67 return FALSE; 68 } 69 70 static int CALLBACK 71 PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam) 72 { 73 // NOTE: This callback is needed to set large icon correctly. 74 HICON hIcon; 75 switch (uMsg) 76 { 77 case PSCB_INITIALIZED: 78 { 79 hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDC_CPLICON_1)); 80 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); 81 break; 82 } 83 } 84 return 0; 85 } 86 87 /* First Applet */ 88 static LONG APIENTRY 89 Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam) 90 { 91 HPROPSHEETPAGE hpsp[MAX_POWER_PAGES]; 92 PROPSHEETHEADER psh; 93 HPSXA hpsxa = NULL; 94 TCHAR Caption[1024]; 95 SYSTEM_POWER_CAPABILITIES spc; 96 LONG ret; 97 98 UNREFERENCED_PARAMETER(uMsg); 99 UNREFERENCED_PARAMETER(wParam); 100 UNREFERENCED_PARAMETER(lParam); 101 102 memset(Caption, 0x0, sizeof(Caption)); 103 LoadString(hApplet, IDS_CPLNAME_1, Caption, sizeof(Caption) / sizeof(TCHAR)); 104 105 ZeroMemory(&psh, sizeof(PROPSHEETHEADER)); 106 psh.dwSize = sizeof(PROPSHEETHEADER); 107 psh.dwFlags = PSH_PROPTITLE | PSH_USEICONID | PSH_USECALLBACK; 108 psh.hwndParent = hwnd; 109 psh.hInstance = hApplet; 110 psh.pszIcon = MAKEINTRESOURCEW(IDC_CPLICON_1); 111 psh.pszCaption = Caption; 112 psh.nPages = 0; 113 psh.nStartPage = 0; 114 psh.phpage = hpsp; 115 psh.pfnCallback = PropSheetProc; 116 117 InitPropSheetPage(&psh, IDD_PROPPAGEPOWERSCHEMES, PowerSchemesDlgProc); 118 if (GetPwrCapabilities(&spc)) 119 { 120 if (spc.SystemBatteriesPresent) 121 { 122 InitPropSheetPage(&psh, IDD_PROPPAGEALARMS, AlarmsDlgProc); 123 } 124 } 125 InitPropSheetPage(&psh, IDD_PROPPAGEADVANCED, AdvancedDlgProc); 126 InitPropSheetPage(&psh, IDD_PROPPAGEHIBERNATE, HibernateDlgProc); 127 128 /* Load additional pages provided by shell extensions */ 129 hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Power"), MAX_POWER_PAGES - psh.nPages); 130 if (hpsxa != NULL) 131 SHAddFromPropSheetExtArray(hpsxa, PropSheetAddPage, (LPARAM)&psh); 132 133 ret = (LONG)(PropertySheet(&psh) != -1); 134 135 if (hpsxa != NULL) 136 SHDestroyPropSheetExtArray(hpsxa); 137 138 return ret; 139 } 140 141 /* Control Panel Callback */ 142 LONG CALLBACK 143 CPlApplet(HWND hwndCPl, 144 UINT uMsg, 145 LPARAM lParam1, 146 LPARAM lParam2) 147 { 148 int i = (int)lParam1; 149 150 switch(uMsg) 151 { 152 case CPL_INIT: 153 { 154 return TRUE; 155 } 156 case CPL_GETCOUNT: 157 { 158 return NUM_APPLETS; 159 } 160 case CPL_INQUIRE: 161 { 162 CPLINFO *CPlInfo = (CPLINFO*)lParam2; 163 CPlInfo->lData = 0; 164 CPlInfo->idIcon = Applets[i].idIcon; 165 CPlInfo->idName = Applets[i].idName; 166 CPlInfo->idInfo = Applets[i].idDescription; 167 break; 168 } 169 case CPL_DBLCLK: 170 { 171 Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); 172 break; 173 } 174 } 175 return FALSE; 176 } 177 178 179 BOOLEAN WINAPI 180 DllMain(HINSTANCE hinstDLL, 181 DWORD dwReason, 182 LPVOID lpvReserved) 183 { 184 UNREFERENCED_PARAMETER(lpvReserved); 185 switch(dwReason) 186 { 187 case DLL_PROCESS_ATTACH: 188 case DLL_THREAD_ATTACH: 189 hApplet = hinstDLL; 190 break; 191 } 192 return TRUE; 193 } 194