Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenadvanced.c
Go to the documentation of this file.
00001 /* $Id: advanced.c 54535 2011-11-29 14:55:58Z dgorbachev $ 00002 * 00003 * PROJECT: ReactOS Power Configuration Applet 00004 * LICENSE: GPL - See COPYING in the top level directory 00005 * FILE: dll/cpl/powercfg/advanced.c 00006 * PURPOSE: advanced tab of applet 00007 * PROGRAMMERS: Alexander Wurzinger (Lohnegrim at gmx dot net) 00008 * Johannes Anderwald (johannes.anderwald@student.tugraz.at) 00009 * Martin Rottensteiner 00010 * Dmitry Chapyshev (lentind@yandex.ru) 00011 */ 00012 00013 //#ifndef NSTATUS 00014 //typedef long NTSTATUS; 00015 //#endif 00016 00017 #include "powercfg.h" 00018 00019 HWND hAdv = 0; 00020 00021 static POWER_ACTION g_SystemBatteries[3]; 00022 static POWER_ACTION g_PowerButton[5]; 00023 static POWER_ACTION g_SleepButton[5]; 00024 00025 00026 static VOID 00027 AddItem(HWND hDlgCtrl, INT ResourceId, LPARAM lParam, POWER_ACTION * lpAction) 00028 { 00029 TCHAR szBuffer[MAX_PATH]; 00030 LRESULT Index; 00031 if (LoadString(hApplet, ResourceId, szBuffer, MAX_PATH) < MAX_PATH) 00032 { 00033 Index = SendMessage(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)szBuffer); 00034 if (Index != CB_ERR) 00035 { 00036 SendMessage(hDlgCtrl, CB_SETITEMDATA, (WPARAM)Index, lParam); 00037 lpAction[Index] = (POWER_ACTION)lParam; 00038 } 00039 } 00040 } 00041 00042 static INT 00043 FindActionIndex(POWER_ACTION * lpAction, DWORD dwActionSize, POWER_ACTION poAction) 00044 { 00045 INT Index; 00046 00047 for (Index = 0; Index < (INT)dwActionSize; Index++) 00048 { 00049 if (lpAction[Index] == poAction) 00050 return Index; 00051 } 00052 00053 return -1; 00054 } 00055 00056 static BOOLEAN 00057 IsBatteryUsed(VOID) 00058 { 00059 SYSTEM_BATTERY_STATE sbs; 00060 00061 if (CallNtPowerInformation(SystemBatteryState,NULL, (ULONG)0, &sbs, sizeof(SYSTEM_BATTERY_STATE)) == STATUS_SUCCESS) 00062 { 00063 if (sbs.BatteryPresent) 00064 { 00065 if (sbs.AcOnLine) 00066 { 00067 return FALSE; 00068 } 00069 return TRUE; 00070 } 00071 } 00072 00073 return FALSE; 00074 } 00075 00076 POWER_ACTION 00077 GetPowerActionFromPolicy(POWER_ACTION_POLICY *Policy) 00078 { 00079 POWER_ACTION poAction = PowerActionNone; 00080 /* 00081 00082 TCHAR szBuffer[MAX_PATH]; 00083 00084 // Note: Windows XP SP2+ does not return the PowerAction code 00085 // for PowerActionWarmEject + PowerActionShutdown but sets it 00086 // to PowerActionNone and sets the Flags & EventCode 00087 00088 00089 _stprintf(szBuffer, L"Action: %x EventCode %x Flags %x",Policy->Action, Policy->EventCode, Policy->Flags); 00090 MessageBoxW(NULL, szBuffer, NULL, MB_OK); 00091 00092 */ 00093 00094 if (Policy->Action == PowerActionNone) 00095 { 00096 if (Policy->Flags == (POWER_ACTION_UI_ALLOWED | POWER_ACTION_QUERY_ALLOWED)) 00097 { 00098 if (Policy->EventCode == POWER_FORCE_TRIGGER_RESET) 00099 { 00100 poAction = PowerActionNone; 00101 } 00102 else if (Policy->EventCode == POWER_USER_NOTIFY_BUTTON) 00103 { 00104 poAction = PowerActionWarmEject; 00105 } 00106 else if (Policy->EventCode == POWER_USER_NOTIFY_SHUTDOWN) 00107 { 00108 poAction = PowerActionShutdown; 00109 } 00110 } 00111 } 00112 else 00113 { 00114 poAction = Policy->Action; 00115 } 00116 00117 return poAction; 00118 } 00119 00120 VOID 00121 ShowCurrentPowerActionPolicy(HWND hDlgCtrl, 00122 POWER_ACTION *lpAction, 00123 DWORD dwActionSize, 00124 POWER_ACTION_POLICY *Policy) 00125 { 00126 int poActionIndex; 00127 POWER_ACTION poAction; 00128 00129 poAction = GetPowerActionFromPolicy(Policy); 00130 poActionIndex = FindActionIndex(lpAction, dwActionSize, poAction); 00131 00132 if (poActionIndex < 0) 00133 { 00134 return; 00135 } 00136 00137 SendMessage(hDlgCtrl, CB_SETCURSEL, (WPARAM)poActionIndex, (LPARAM)0); 00138 } 00139 00140 BOOLEAN 00141 SaveCurrentPowerActionPolicy(IN HWND hDlgCtrl, 00142 OUT POWER_ACTION_POLICY *Policy) 00143 { 00144 LRESULT Index; 00145 LRESULT ItemData; 00146 00147 Index = SendMessage(hDlgCtrl, CB_GETCURSEL, 0, 0); 00148 if (Index == CB_ERR) 00149 return FALSE; 00150 00151 ItemData = SendMessage(hDlgCtrl, CB_GETITEMDATA, (WPARAM)Index, 0); 00152 if (ItemData == CB_ERR) 00153 return FALSE; 00154 00155 switch(ItemData) 00156 { 00157 case PowerActionNone: 00158 Policy->Action = PowerActionNone; 00159 Policy->EventCode = POWER_FORCE_TRIGGER_RESET; 00160 break; 00161 case PowerActionWarmEject: 00162 Policy->Action = PowerActionNone; 00163 Policy->EventCode = POWER_USER_NOTIFY_BUTTON; 00164 break; 00165 case PowerActionShutdown: 00166 Policy->Action = PowerActionNone; 00167 Policy->EventCode = POWER_USER_NOTIFY_SHUTDOWN; 00168 break; 00169 case PowerActionSleep: 00170 case PowerActionHibernate: 00171 Policy->Action = (POWER_ACTION)ItemData; 00172 Policy->EventCode = 0; 00173 break; 00174 default: 00175 return FALSE; 00176 } 00177 Policy->Flags = (POWER_ACTION_UI_ALLOWED | POWER_ACTION_QUERY_ALLOWED); 00178 00179 return TRUE; 00180 } 00181 00182 00183 //------------------------------------------------------------------- 00184 00185 VOID 00186 ShowCurrentPowerActionPolicies(HWND hwndDlg) 00187 { 00188 TCHAR szAction[MAX_PATH]; 00189 00190 if (!IsBatteryUsed()) 00191 { 00192 #if 0 00193 /* expiremental code */ 00194 // ShowCurrentPowerButtonAcAction(hList2, 00195 ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON), 00196 g_SystemBatteries, 00197 sizeof(g_SystemBatteries) / sizeof(POWER_ACTION), 00198 &gGPP.user.LidCloseAc); 00199 #else 00200 if (LoadString(hApplet, IDS_PowerActionNone1+gGPP.user.LidCloseAc.Action, szAction, MAX_PATH)) 00201 { 00202 SendDlgItemMessage(hwndDlg, IDC_LIDCLOSE, 00203 CB_SELECTSTRING, 00204 TRUE, 00205 (LPARAM)szAction); 00206 } 00207 #endif 00208 ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON), 00209 g_PowerButton, 00210 sizeof(g_PowerButton) / sizeof(POWER_ACTION), 00211 &gGPP.user.PowerButtonAc); 00212 00213 #if 0 00214 /* expiremental code */ 00215 ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_SLEEPBUTTON), 00216 g_SleepButton, 00217 sizeof(g_SleepButton) / sizeof(POWER_ACTION), 00218 &gGPP.user.SleepButtonAc); 00219 #else 00220 if (LoadString(hApplet, IDS_PowerActionNone1+gGPP.user.SleepButtonAc.Action, szAction, MAX_PATH)) 00221 { 00222 SendDlgItemMessage(hwndDlg, IDC_SLEEPBUTTON, 00223 CB_SELECTSTRING, 00224 TRUE, 00225 (LPARAM)szAction); 00226 } 00227 #endif 00228 } 00229 else 00230 { 00231 #if 0 00232 00233 ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_LIDCLOSE), 00234 g_SleepButton, 00235 sizeof(g_SleepButton) / sizeof(POWER_ACTION), 00236 &gGPP.user.LidCloseDc); 00237 00238 ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON), 00239 g_SleepButton, 00240 sizeof(g_SleepButton) / sizeof(POWER_ACTION), 00241 &gGPP.user.PowerButtonDc); 00242 00243 ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_SLEEPBUTTON), 00244 g_SleepButton, 00245 sizeof(g_SleepButton) / sizeof(POWER_ACTION), 00246 &gGPP.user.SleepButtonDc); 00247 #else 00248 if (LoadString(hApplet, IDS_PowerActionNone1+gGPP.user.LidCloseDc.Action, szAction, MAX_PATH)) 00249 { 00250 SendDlgItemMessage(hwndDlg, IDC_LIDCLOSE, 00251 CB_SELECTSTRING, 00252 TRUE, 00253 (LPARAM)szAction); 00254 } 00255 if (LoadString(hApplet, IDS_PowerActionNone1+gGPP.user.PowerButtonDc.Action, szAction, MAX_PATH)) 00256 { 00257 SendDlgItemMessage(hwndDlg, IDC_POWERBUTTON, 00258 CB_SELECTSTRING, 00259 TRUE, 00260 (LPARAM)szAction); 00261 } 00262 if (LoadString(hApplet, IDS_PowerActionNone1+gGPP.user.SleepButtonDc.Action, szAction, MAX_PATH)) 00263 { 00264 SendDlgItemMessage(hwndDlg, IDC_SLEEPBUTTON, 00265 CB_SELECTSTRING, 00266 TRUE, 00267 (LPARAM)szAction); 00268 } 00269 #endif 00270 } 00271 } 00272 00273 VOID 00274 Adv_InitDialog(VOID) 00275 { 00276 HWND hList1; 00277 HWND hList2; 00278 HWND hList3; 00279 00280 BOOLEAN bSuspend = FALSE; 00281 BOOLEAN bHibernate; 00282 BOOLEAN bShutdown; 00283 00284 SYSTEM_POWER_CAPABILITIES spc; 00285 00286 CheckDlgButton(hAdv, 00287 IDC_SYSTRAYBATTERYMETER, 00288 gGPP.user.GlobalFlags & EnableSysTrayBatteryMeter ? BST_CHECKED : BST_UNCHECKED); 00289 CheckDlgButton(hAdv, 00290 IDC_PASSWORDLOGON, 00291 gGPP.user.GlobalFlags & EnablePasswordLogon ? BST_CHECKED : BST_UNCHECKED); 00292 CheckDlgButton(hAdv, 00293 IDC_VIDEODIMDISPLAY, 00294 gGPP.user.GlobalFlags & EnableVideoDimDisplay ? BST_CHECKED : BST_UNCHECKED); 00295 00296 GetPwrCapabilities(&spc); 00297 00298 if (spc.SystemS1 || spc.SystemS2 || spc.SystemS3) 00299 bSuspend=TRUE; 00300 00301 bHibernate = spc.HiberFilePresent; 00302 bShutdown = spc.SystemS5; 00303 00304 hList1 = GetDlgItem(hAdv, IDC_LIDCLOSE); 00305 SendMessage(hList1, CB_RESETCONTENT, 0, 0); 00306 00307 memset(g_SystemBatteries, 0x0, sizeof(g_SystemBatteries)); 00308 if (spc.SystemBatteriesPresent) 00309 { 00310 AddItem(hList1, IDS_PowerActionNone1, (LPARAM)PowerActionNone, g_SystemBatteries); 00311 00312 if (bSuspend) 00313 { 00314 AddItem(hList1, IDS_PowerActionSleep, (LPARAM)PowerActionSleep, g_SystemBatteries); 00315 } 00316 00317 if (bHibernate) 00318 { 00319 AddItem(hList1, IDS_PowerActionHibernate, (LPARAM)PowerActionHibernate, g_SystemBatteries); 00320 } 00321 } 00322 else 00323 { 00324 ShowWindow(GetDlgItem(hAdv, IDC_VIDEODIMDISPLAY), FALSE); 00325 ShowWindow(GetDlgItem(hAdv, IDC_SLIDCLOSE), FALSE); 00326 ShowWindow(hList1, FALSE); 00327 } 00328 00329 hList2 = GetDlgItem(hAdv, IDC_POWERBUTTON); 00330 SendMessage(hList2, CB_RESETCONTENT, 0, 0); 00331 00332 memset(g_PowerButton, 0x0, sizeof(g_PowerButton)); 00333 if (spc.PowerButtonPresent) 00334 { 00335 AddItem(hList2, IDS_PowerActionNone1, (LPARAM)PowerActionNone, g_PowerButton); 00336 AddItem(hList2, IDS_PowerActionWarmEject, (LPARAM)PowerActionWarmEject, g_PowerButton); 00337 00338 if (bSuspend) 00339 { 00340 AddItem(hList2, IDS_PowerActionSleep, (LPARAM)PowerActionSleep, g_PowerButton); 00341 } 00342 00343 if (bHibernate) 00344 { 00345 AddItem(hList2, IDS_PowerActionHibernate, (LPARAM)PowerActionHibernate, g_PowerButton); 00346 00347 } 00348 if (bShutdown) 00349 { 00350 AddItem(hList2, IDS_PowerActionShutdown, (LPARAM)PowerActionShutdown, g_PowerButton); 00351 } 00352 } 00353 else 00354 { 00355 ShowWindow(GetDlgItem(hAdv, IDC_SPOWERBUTTON), FALSE); 00356 ShowWindow(hList2, FALSE); 00357 } 00358 00359 hList3=GetDlgItem(hAdv, IDC_SLEEPBUTTON); 00360 SendMessage(hList3, CB_RESETCONTENT, 0, 0); 00361 memset(g_SleepButton, 0x0, sizeof(g_SleepButton)); 00362 00363 if (spc.SleepButtonPresent) 00364 { 00365 AddItem(hList3, IDS_PowerActionNone1, (LPARAM)PowerActionNone, g_SleepButton); 00366 AddItem(hList3, IDS_PowerActionWarmEject, (LPARAM)PowerActionWarmEject, g_SleepButton); 00367 00368 if (bSuspend) 00369 { 00370 AddItem(hList3, IDS_PowerActionSleep, (LPARAM)PowerActionSleep, g_SleepButton); 00371 } 00372 00373 if (bHibernate) 00374 { 00375 AddItem(hList3, IDS_PowerActionHibernate, (LPARAM)PowerActionHibernate, g_SleepButton); 00376 } 00377 00378 if (bShutdown) 00379 { 00380 AddItem(hList3, IDS_PowerActionShutdown, (LPARAM)PowerActionShutdown, g_SleepButton); 00381 } 00382 } 00383 else 00384 { 00385 ShowWindow(GetDlgItem(hAdv, IDC_SSLEEPBUTTON), FALSE); 00386 ShowWindow(hList3, FALSE); 00387 } 00388 00389 if (ReadGlobalPwrPolicy(&gGPP)) 00390 { 00391 ShowCurrentPowerActionPolicies(hAdv); 00392 } 00393 } 00394 00395 static VOID 00396 Adv_SaveData(HWND hwndDlg) 00397 { 00398 BOOL bSystrayBatteryMeter; 00399 BOOL bPasswordLogon; 00400 BOOL bVideoDimDisplay; 00401 00402 bSystrayBatteryMeter = 00403 (IsDlgButtonChecked(hwndDlg, IDC_SYSTRAYBATTERYMETER) == BST_CHECKED); 00404 00405 bPasswordLogon = 00406 (IsDlgButtonChecked(hwndDlg, IDC_PASSWORDLOGON) == BST_CHECKED); 00407 00408 bVideoDimDisplay = 00409 (IsDlgButtonChecked(hwndDlg, IDC_VIDEODIMDISPLAY) == BST_CHECKED); 00410 00411 if (bSystrayBatteryMeter) 00412 { 00413 if (!(gGPP.user.GlobalFlags & EnableSysTrayBatteryMeter)) 00414 { 00415 gGPP.user.GlobalFlags = gGPP.user.GlobalFlags + EnableSysTrayBatteryMeter; 00416 } 00417 } 00418 else 00419 { 00420 if ((gGPP.user.GlobalFlags & EnableSysTrayBatteryMeter)) 00421 { 00422 gGPP.user.GlobalFlags = gGPP.user.GlobalFlags - EnableSysTrayBatteryMeter; 00423 } 00424 } 00425 00426 if (bPasswordLogon) 00427 { 00428 if (!(gGPP.user.GlobalFlags & EnablePasswordLogon)) 00429 { 00430 gGPP.user.GlobalFlags = gGPP.user.GlobalFlags + EnablePasswordLogon; 00431 } 00432 } 00433 else 00434 { 00435 if ((gGPP.user.GlobalFlags & EnablePasswordLogon)) 00436 { 00437 gGPP.user.GlobalFlags = gGPP.user.GlobalFlags - EnablePasswordLogon; 00438 } 00439 } 00440 00441 if (bVideoDimDisplay) 00442 { 00443 if (!(gGPP.user.GlobalFlags & EnableVideoDimDisplay)) 00444 { 00445 gGPP.user.GlobalFlags = gGPP.user.GlobalFlags + EnableVideoDimDisplay; 00446 } 00447 } 00448 else 00449 { 00450 if ((gGPP.user.GlobalFlags & EnableVideoDimDisplay)) 00451 { 00452 gGPP.user.GlobalFlags = gGPP.user.GlobalFlags - EnableVideoDimDisplay; 00453 } 00454 } 00455 00456 if (!IsBatteryUsed()) 00457 { 00458 SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON), &gGPP.user.PowerButtonAc); 00459 #if 0 00460 SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_LIDCLOSE), &gGPP.user.LidCloseAc); 00461 SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_SLEEPBUTTON), &gGPP.user.SleepButtonAc); 00462 #endif 00463 } 00464 else 00465 { 00466 #if 0 00467 SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON), &gGPP.user.PowerButtonDc); 00468 SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_LIDCLOSE), &gGPP.user.LidCloseDc); 00469 SaveCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_SLEEPBUTTON), &gGPP.user.SleepButtonDc); 00470 #endif 00471 } 00472 00473 if (!WriteGlobalPwrPolicy(&gGPP)) 00474 { 00475 MessageBox(hwndDlg, L"WriteGlobalPwrPolicy failed", NULL, MB_OK); 00476 } 00477 00478 Adv_InitDialog(); 00479 } 00480 00481 /* Property page dialog callback */ 00482 INT_PTR CALLBACK 00483 AdvancedDlgProc(HWND hwndDlg, 00484 UINT uMsg, 00485 WPARAM wParam, 00486 LPARAM lParam) 00487 { 00488 switch(uMsg) 00489 { 00490 case WM_INITDIALOG: 00491 hAdv = hwndDlg; 00492 Adv_InitDialog(); 00493 return TRUE; 00494 break; 00495 case WM_COMMAND: 00496 switch(LOWORD(wParam)) 00497 { 00498 case IDC_SYSTRAYBATTERYMETER: 00499 case IDC_PASSWORDLOGON: 00500 case IDC_VIDEODIMDISPLAY: 00501 if (HIWORD(wParam) == BN_CLICKED) 00502 { 00503 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00504 } 00505 break; 00506 case IDC_LIDCLOSE: 00507 case IDC_POWERBUTTON: 00508 case IDC_SLEEPBUTTON: 00509 if (HIWORD(wParam) == CBN_SELCHANGE) 00510 { 00511 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00512 } 00513 break; 00514 } 00515 break; 00516 case WM_NOTIFY: 00517 { 00518 LPNMHDR lpnm = (LPNMHDR)lParam; 00519 if (lpnm->code == (UINT)PSN_APPLY) 00520 { 00521 Adv_SaveData(hwndDlg); 00522 } 00523 return TRUE; 00524 } 00525 } 00526 return FALSE; 00527 } Generated on Sun May 27 2012 04:20:57 for ReactOS by
1.7.6.1
|