Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

727 lines
21 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1996
  4. *
  5. * TITLE: POWERCFG.C
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: ReedB
  10. *
  11. * DATE: 17 Oct, 1996
  12. *
  13. * DESCRIPTION:
  14. * Power management UI. Control panel applet.
  15. *
  16. *******************************************************************************/
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <commctrl.h>
  22. #include <shlobj.h>
  23. #include <shlobjp.h>
  24. #include <shlwapi.h>
  25. #include <cpl.h>
  26. #include <help.h>
  27. #include <regstr.h>
  28. #include "powercfg.h"
  29. #include "pwrresid.h"
  30. #include <shfusion.h>
  31. /*******************************************************************************
  32. *
  33. * G L O B A L D A T A
  34. *
  35. *******************************************************************************/
  36. HINSTANCE g_hInstance; // Global instance handle of this DLL.
  37. UINT wHelpMessage; // Registered help message.
  38. // Registry path to optional top level powercfg pages.
  39. TCHAR g_szRegOptionalPages[] = REGSTR_PATH_CONTROLSFOLDER TEXT("\\Power");
  40. // Array which defines the property tabs/pages in the applet.
  41. // The contents of this array are built dynamically, since they
  42. // depend on the machine power management capabilities.
  43. POWER_PAGES g_TopLevelPages[MAX_PAGES] =
  44. {
  45. MAKEINTRESOURCE(IDS_APPNAME), NULL, 0, // Caption
  46. 0, NULL, 0,
  47. 0, NULL, 0,
  48. 0, NULL, 0,
  49. 0, NULL, 0,
  50. 0, NULL, 0,
  51. 0, NULL, 0,
  52. 0, NULL, 0,
  53. 0, NULL, 0,
  54. 0, NULL, 0,
  55. 0, NULL, 0,
  56. 0, NULL, 0,
  57. 0, NULL, 0,
  58. 0, NULL, 0,
  59. 0, NULL, 0,
  60. 0, NULL, 0,
  61. 0, NULL, 0,
  62. 0, NULL, 0
  63. };
  64. // Specifies which OS, filled in at init CPL time.
  65. BOOL g_bRunningUnderNT;
  66. // This structure is filled in by the Power Policy Manager at CPL_INIT time.
  67. SYSTEM_POWER_CAPABILITIES g_SysPwrCapabilities;
  68. // The following globals are derived from g_SysPwrCapabilities:
  69. DWORD g_dwNumSleepStates = 1; // Every one suports PowerSystemWorking.
  70. DWORD g_dwSleepStatesMaxMin; // Specs sleep states slider range.
  71. DWORD g_dwBattryLevelMaxMin; // Specs battery level slider range.
  72. DWORD g_dwFanThrottleMaxMin; // Specs fan throttle slider range.
  73. BOOL g_bVideoLowPowerSupported;// This will be moved to g_SysPwrCapabilities
  74. UINT g_uiVideoTimeoutMaxMin; // May be set from registry.
  75. UINT g_uiSpindownMaxMin; // May be set from registry.
  76. PUINT g_puiBatCount; // Number of displayable batteries.
  77. BOOL g_bIsUserAdministrator; // The current user has admin. privileges.
  78. // Static flags:
  79. UINT g_uiOverrideAppsFlag = POWER_ACTION_OVERRIDE_APPS;
  80. UINT g_uiDisableWakesFlag = POWER_ACTION_DISABLE_WAKES;
  81. int BuildPages(PSYSTEM_POWER_CAPABILITIES, PPOWER_PAGES);
  82. VOID SyncRegPPM(VOID);
  83. /*******************************************************************************
  84. *
  85. * P U B L I C E N T R Y P O I N T S
  86. *
  87. *******************************************************************************/
  88. /*******************************************************************************
  89. *
  90. * DllInitialize
  91. *
  92. * DESCRIPTION:
  93. * Library entry point
  94. *
  95. * PARAMETERS:
  96. *
  97. *******************************************************************************/
  98. BOOL DllInitialize(
  99. IN PVOID hmod,
  100. IN ULONG ulReason,
  101. IN PCONTEXT pctx OPTIONAL)
  102. {
  103. UNREFERENCED_PARAMETER(pctx);
  104. switch (ulReason) {
  105. case DLL_PROCESS_ATTACH:
  106. g_hInstance = hmod;
  107. DisableThreadLibraryCalls(g_hInstance);
  108. wHelpMessage = RegisterWindowMessage(TEXT("ShellHelp"));
  109. InitSchemesList();
  110. SHFusionInitializeFromModuleID(hmod, 124);
  111. break;
  112. case DLL_PROCESS_DETACH:
  113. SHFusionUninitialize();
  114. break;
  115. }
  116. return TRUE;
  117. }
  118. /*******************************************************************************
  119. *
  120. * CplApplet
  121. *
  122. * DESCRIPTION:
  123. * Called by control panel.
  124. *
  125. * PARAMETERS:
  126. *
  127. *******************************************************************************/
  128. LRESULT APIENTRY
  129. CPlApplet(
  130. HWND hCPLWnd,
  131. UINT Message,
  132. LPARAM wParam,
  133. LPARAM lParam
  134. )
  135. {
  136. LPNEWCPLINFO lpNewCPLInfo;
  137. LPCPLINFO lpCPlInfo;
  138. WNDCLASS cls;
  139. DWORD dwSize, dwSessionId, dwTry = 0;
  140. OSVERSIONINFO osvi;
  141. switch (Message) {
  142. case CPL_INIT: // Is there an applet ?
  143. // Set OS global.
  144. osvi.dwOSVersionInfoSize = sizeof(osvi);
  145. GetVersionEx(&osvi);
  146. g_bRunningUnderNT = (osvi.dwMajorVersion >= 5) &&
  147. (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT);
  148. // If we're running under NT don't allow power management UI
  149. // unless we have power management capabilities.
  150. if (g_bRunningUnderNT) {
  151. if (!PowerCapabilities()) {
  152. return FALSE;
  153. }
  154. }
  155. // Set global variables based on the machine capabilities.
  156. return InitCapabilities(&g_SysPwrCapabilities);
  157. case CPL_GETCOUNT: // PowerCfg.Cpl supports one applet.
  158. return 1;
  159. case CPL_INQUIRE: // Fill CplInfo structure
  160. lpCPlInfo = (LPCPLINFO)lParam;
  161. lpCPlInfo->idIcon = IDI_PWRMNG;
  162. lpCPlInfo->idName = IDS_APPNAME;
  163. lpCPlInfo->idInfo = IDS_INFO; // we have to use this in order to support infotips greater than 64 chars, which
  164. // is the max that the NEWCPLINFO struct supports
  165. lpCPlInfo->lData = 0;
  166. return 1;
  167. case CPL_NEWINQUIRE:
  168. lpNewCPLInfo = (LPNEWCPLINFO)lParam;
  169. memset(lpNewCPLInfo, 0, sizeof(NEWCPLINFO));
  170. lpNewCPLInfo->dwSize = sizeof(NEWCPLINFO);
  171. lpNewCPLInfo->hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_PWRMNG));
  172. LoadString(g_hInstance, IDS_APPNAME, lpNewCPLInfo->szName, ARRAYSIZE(lpNewCPLInfo->szName));
  173. LoadString(g_hInstance, IDS_INFO, lpNewCPLInfo->szInfo, ARRAYSIZE(lpNewCPLInfo->szInfo));
  174. lpNewCPLInfo->szHelpFile[0] = TEXT('\0');
  175. return 1;
  176. case CPL_DBLCLK: // This applet has been chosen to run
  177. case CPL_STARTWPARMS: // Started from RUNDLL
  178. // Initialize the common controls.
  179. InitCommonControls();
  180. // Sync the current scheme registry and PPM.
  181. SyncRegPPM();
  182. // Build the displayed pages base on system capabilities.
  183. BuildPages(&g_SysPwrCapabilities, g_TopLevelPages);
  184. // Will return FALSE if we didn't display any pages.
  185. return DoPropSheetPages(hCPLWnd, &(g_TopLevelPages[0]),
  186. g_szRegOptionalPages);
  187. case CPL_EXIT: // This applet must die
  188. case CPL_STOP:
  189. break;
  190. case CPL_SELECT: // This applet has been selected
  191. break;
  192. }
  193. return FALSE;
  194. }
  195. /*******************************************************************************
  196. *
  197. * LoadDynamicString
  198. *
  199. * DESCRIPTION:
  200. * Wrapper for the FormatMessage function that loads a string from our
  201. * resource table into a dynamically allocated buffer, optionally filling
  202. * it with the variable arguments passed.
  203. *
  204. * PARAMETERS:
  205. * StringID, resource identifier of the string to use.
  206. * (optional), parameters to use to format the string message.
  207. *
  208. *******************************************************************************/
  209. LPTSTR CDECL LoadDynamicString( UINT StringID, ... )
  210. {
  211. va_list Marker;
  212. TCHAR Buffer[256];
  213. LPTSTR pStr;
  214. int iLen;
  215. // va_start is a macro...it breaks when you use it as an assign...on ALPHA.
  216. va_start(Marker, StringID);
  217. iLen = LoadString(g_hInstance, StringID, Buffer, ARRAYSIZE(Buffer));
  218. if (iLen == 0) {
  219. MYDBGPRINT(( "LoadDynamicString: LoadString on: %X failed", StringID));
  220. return NULL;
  221. }
  222. FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  223. (LPVOID) (LPTSTR) Buffer, 0, 0, (LPTSTR) &pStr, 0, &Marker);
  224. va_end(Marker);
  225. return pStr;
  226. }
  227. /*******************************************************************************
  228. *
  229. * DisplayFreeStr
  230. *
  231. * DESCRIPTION:
  232. *
  233. * PARAMETERS:
  234. *
  235. *******************************************************************************/
  236. LPTSTR DisplayFreeStr(HWND hWnd, UINT uID, LPTSTR pStr, BOOL bFree)
  237. {
  238. if (pStr) {
  239. SetDlgItemText(hWnd, uID, pStr);
  240. ShowWindow(GetDlgItem(hWnd, uID), SW_SHOWNOACTIVATE);
  241. if (bFree) {
  242. LocalFree(pStr);
  243. return NULL;
  244. }
  245. }
  246. else {
  247. ShowWindow(GetDlgItem(hWnd, uID), SW_HIDE);
  248. }
  249. return pStr;
  250. }
  251. /*******************************************************************************
  252. *
  253. * ValidateUISchemeFields
  254. *
  255. * DESCRIPTION:
  256. * Validate only the data values which are set by our UI.
  257. *
  258. * PARAMETERS:
  259. *
  260. *******************************************************************************/
  261. BOOLEAN ValidateUISchemeFields(PPOWER_POLICY ppp)
  262. {
  263. POWER_POLICY pp;
  264. static PGLOBAL_POWER_POLICY pgpp;
  265. memcpy(&pp, ppp, sizeof(pp));
  266. if (ValidatePowerPolicies(NULL, &pp)) {
  267. if (g_SysPwrCapabilities.HiberFilePresent) {
  268. ppp->mach.DozeS4TimeoutAc = pp.mach.DozeS4TimeoutAc;
  269. ppp->mach.DozeS4TimeoutDc = pp.mach.DozeS4TimeoutDc;
  270. }
  271. if (g_SysPwrCapabilities.SystemS1 ||
  272. g_SysPwrCapabilities.SystemS2 ||
  273. g_SysPwrCapabilities.SystemS3) {
  274. ppp->user.IdleTimeoutAc = pp.user.IdleTimeoutAc;
  275. ppp->user.IdleTimeoutDc = pp.user.IdleTimeoutDc;
  276. }
  277. if (g_bVideoLowPowerSupported) {
  278. ppp->user.VideoTimeoutAc = pp.user.VideoTimeoutAc;
  279. ppp->user.VideoTimeoutDc = pp.user.VideoTimeoutDc;
  280. }
  281. if (g_SysPwrCapabilities.DiskSpinDown) {
  282. ppp->user.SpindownTimeoutAc = pp.user.SpindownTimeoutAc;
  283. ppp->user.SpindownTimeoutDc = pp.user.SpindownTimeoutDc;
  284. }
  285. return TRUE;
  286. }
  287. return FALSE;
  288. }
  289. /*******************************************************************************
  290. *
  291. * GetGlobalPwrPolicy
  292. *
  293. * DESCRIPTION:
  294. * Read the global power policy and validate only the data values which are
  295. * set by our UI.
  296. *
  297. * PARAMETERS:
  298. *
  299. *******************************************************************************/
  300. BOOLEAN GetGlobalPwrPolicy(PGLOBAL_POWER_POLICY pgpp)
  301. {
  302. int i;
  303. GLOBAL_POWER_POLICY gpp;
  304. if (ReadGlobalPwrPolicy(pgpp)) {
  305. memcpy(&gpp, pgpp, sizeof(gpp));
  306. if (ValidatePowerPolicies(&gpp, NULL)) {
  307. if (g_SysPwrCapabilities.PowerButtonPresent &&
  308. !g_SysPwrCapabilities.SleepButtonPresent) {
  309. pgpp->user.PowerButtonAc = gpp.user.PowerButtonAc;
  310. pgpp->user.PowerButtonDc = gpp.user.PowerButtonDc;
  311. }
  312. if (g_SysPwrCapabilities.LidPresent) {
  313. pgpp->user.LidCloseAc = gpp.user.LidCloseAc;
  314. pgpp->user.LidCloseDc = gpp.user.LidCloseDc;
  315. }
  316. if (g_SysPwrCapabilities.SystemBatteriesPresent) {
  317. for (i = 0; i < NUM_DISCHARGE_POLICIES; i++) {
  318. pgpp->user.DischargePolicy[i] = gpp.user.DischargePolicy[i];
  319. }
  320. }
  321. pgpp->user.GlobalFlags = gpp.user.GlobalFlags;
  322. return TRUE;
  323. }
  324. }
  325. return FALSE;
  326. }
  327. /*******************************************************************************
  328. *
  329. * ErrorMsgBox
  330. *
  331. * DESCRIPTION:
  332. * Display a messag box for system message strings specified by dwErr and
  333. * title string specified by uiTitleID.
  334. *
  335. * PARAMETERS:
  336. *
  337. *******************************************************************************/
  338. int ErrorMsgBox(
  339. HWND hwnd,
  340. DWORD dwErr,
  341. UINT uiTitleID)
  342. {
  343. LPTSTR pszErr = NULL;
  344. LPTSTR pszTitle = NULL;
  345. TCHAR szUnknownErr[64];
  346. UINT idRet;
  347. if (dwErr == NO_ERROR)
  348. {
  349. dwErr = GetLastError();
  350. }
  351. pszTitle = LoadDynamicString(uiTitleID);
  352. if (dwErr != NO_ERROR)
  353. {
  354. FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  355. NULL, dwErr, 0, (LPTSTR)&pszErr, 1, NULL);
  356. }
  357. if (NULL == pszErr)
  358. {
  359. LoadString(g_hInstance, IDS_UNKNOWN_ERROR, szUnknownErr, ARRAYSIZE(szUnknownErr));
  360. pszErr = szUnknownErr;
  361. }
  362. idRet = MessageBox(hwnd, pszErr, pszTitle, MB_ICONEXCLAMATION);
  363. if (pszTitle)
  364. {
  365. LocalFree(pszTitle);
  366. }
  367. if ((pszErr) && (pszErr != szUnknownErr))
  368. {
  369. LocalFree(pszErr);
  370. }
  371. return idRet;
  372. }
  373. /*******************************************************************************
  374. *
  375. * WritePwrSchemeReport
  376. *
  377. * DESCRIPTION:
  378. * Cover for WritePwrScheme with error reporting.
  379. *
  380. * PARAMETERS:
  381. *
  382. *******************************************************************************/
  383. BOOLEAN WritePwrSchemeReport(
  384. HWND hwnd,
  385. PUINT puiID,
  386. LPTSTR lpszSchemeName,
  387. LPTSTR lpszDescription,
  388. PPOWER_POLICY lpScheme
  389. )
  390. {
  391. if (WritePwrScheme(puiID, lpszSchemeName, lpszDescription, lpScheme)) {
  392. return TRUE;
  393. }
  394. else {
  395. ErrorMsgBox(hwnd, NO_ERROR, IDS_UNABLETOSETPOLICY);
  396. return FALSE;
  397. }
  398. }
  399. /*******************************************************************************
  400. *
  401. * WriteGlobalPwrPolicyReport
  402. *
  403. * DESCRIPTION:
  404. * Cover for WriteGlobalPwrPolicy with error reporting.
  405. *
  406. * PARAMETERS:
  407. *
  408. *******************************************************************************/
  409. BOOLEAN WriteGlobalPwrPolicyReport(
  410. HWND hwnd,
  411. PGLOBAL_POWER_POLICY pgpp,
  412. BOOL fDisplayErrorUI
  413. )
  414. {
  415. if (WriteGlobalPwrPolicy(pgpp))
  416. {
  417. return TRUE;
  418. }
  419. else
  420. {
  421. if (fDisplayErrorUI)
  422. {
  423. ErrorMsgBox(hwnd, NO_ERROR, IDS_UNABLETOSETGLOBALPOLICY);
  424. }
  425. return FALSE;
  426. }
  427. }
  428. /*******************************************************************************
  429. *
  430. * SetActivePwrSchemeReport
  431. *
  432. * DESCRIPTION:
  433. * Cover for WriteGlobalPwrPolicy with error reporting.
  434. *
  435. * PARAMETERS:
  436. *
  437. *******************************************************************************/
  438. BOOLEAN SetActivePwrSchemeReport(
  439. HWND hwnd,
  440. UINT uiID,
  441. PGLOBAL_POWER_POLICY pgpp,
  442. PPOWER_POLICY ppp)
  443. {
  444. if (SetActivePwrScheme(uiID, pgpp, ppp)) {
  445. return TRUE;
  446. }
  447. else {
  448. ErrorMsgBox(hwnd, NO_ERROR, IDS_UNABLETOSETACTIVEPOLICY);
  449. return FALSE;
  450. }
  451. }
  452. /*******************************************************************************
  453. *
  454. * P R I V A T E F U N C T I O N S
  455. *
  456. *******************************************************************************/
  457. /*******************************************************************************
  458. *
  459. * BuildPages
  460. *
  461. * DESCRIPTION:
  462. * Build the g_TopLevelPages array based on the machine capabilities. The
  463. * order of the tabs\pages is set here.
  464. *
  465. * PARAMETERS:
  466. *
  467. *******************************************************************************/
  468. int BuildPages(PSYSTEM_POWER_CAPABILITIES pspc, PPOWER_PAGES ppp)
  469. {
  470. int iPageCount = 1; // We always have at least the power scheme page.
  471. // Do we have system batteries? Different dialog templates will be used
  472. // depending on the answer to this question.
  473. if (pspc->SystemBatteriesPresent) {
  474. AppendPropSheetPage(ppp, IDD_POWERSCHEME, PowerSchemeDlgProc);
  475. AppendPropSheetPage(ppp, IDD_ALARMPOLICY, AlarmDlgProc);
  476. iPageCount++;
  477. // Is there a battery driver that the battery meter can query?
  478. if (BatMeterCapabilities(&g_puiBatCount)) {
  479. AppendPropSheetPage(ppp, IDD_BATMETERCFG, BatMeterCfgDlgProc);
  480. iPageCount++;
  481. }
  482. }
  483. else {
  484. // No battery pages.
  485. AppendPropSheetPage(ppp, IDD_POWERSCHEME_NOBAT, PowerSchemeDlgProc);
  486. }
  487. // Always show the Advanced page.
  488. AppendPropSheetPage(ppp, IDD_ADVANCEDPOLICY, AdvancedDlgProc);
  489. iPageCount++;
  490. // Can we put up the hibernate page?
  491. if (pspc->SystemS4) {
  492. AppendPropSheetPage(ppp, IDD_HIBERNATE, HibernateDlgProc);
  493. iPageCount++;
  494. }
  495. #ifdef WINNT
  496. if (pspc->ApmPresent) {
  497. //
  498. // Is APM present on the machine? This page is
  499. // not shown if ACPI is present
  500. //
  501. AppendPropSheetPage(ppp, IDD_APM, APMDlgProc);
  502. iPageCount++;
  503. }
  504. if (pspc->UpsPresent) {
  505. AppendPropSheetPage(ppp, IDD_UPS, UPSMainPageProc);
  506. iPageCount++;
  507. }
  508. #endif
  509. return iPageCount;
  510. }
  511. /*******************************************************************************
  512. *
  513. * InitCapabilities
  514. *
  515. * DESCRIPTION:
  516. * Call down to the PPM to get power management capabilities and set
  517. * global variables based on the results.
  518. *
  519. * PARAMETERS:
  520. *
  521. *******************************************************************************/
  522. BOOL InitCapabilities(PSYSTEM_POWER_CAPABILITIES pspc)
  523. {
  524. UINT i, uiGran = 0, uiMax, uiMin;
  525. ADMINISTRATOR_POWER_POLICY app;
  526. int dummy;
  527. // Set hard limits. These may be overridden by optional registry values.
  528. g_uiVideoTimeoutMaxMin = MAKELONG((short) MAX_VIDEO_TIMEOUT, (short) 1);
  529. g_uiSpindownMaxMin = MAKELONG((short) MAX_SPINDOWN_TIMEOUT,(short) 1);
  530. g_dwNumSleepStates = 0;
  531. if (!GetPwrCapabilities(pspc)) {
  532. return FALSE;
  533. }
  534. if (pspc->SystemS1) {
  535. g_dwNumSleepStates++;
  536. }
  537. if (pspc->SystemS2) {
  538. g_dwNumSleepStates++;
  539. }
  540. if (pspc->SystemS3) {
  541. g_dwNumSleepStates++;
  542. }
  543. if (pspc->SystemS4) {
  544. g_dwNumSleepStates++;
  545. }
  546. // Get administrator overrides if present.
  547. if (IsAdminOverrideActive(&app)) {
  548. if (app.MaxVideoTimeout > -1) {
  549. uiMin = LOWORD(g_uiVideoTimeoutMaxMin);
  550. uiMax = app.MaxVideoTimeout;
  551. g_uiVideoTimeoutMaxMin = MAKELONG((short) uiMax,(short) uiMin);
  552. }
  553. if (app.MaxSleep < PowerSystemHibernate) {
  554. g_dwNumSleepStates = (DWORD)app.MaxSleep;
  555. }
  556. }
  557. // Get the optional disk spindown timeout range.
  558. if (GetPwrDiskSpindownRange(&uiMax, &uiMin)) {
  559. g_uiSpindownMaxMin = MAKELONG((short) uiMax,(short) uiMin);
  560. }
  561. if (g_dwNumSleepStates > 1) {
  562. g_dwSleepStatesMaxMin =
  563. MAKELONG((short) 0, (short) g_dwNumSleepStates - 1);
  564. }
  565. g_dwBattryLevelMaxMin = MAKELONG((short)0, (short)100);
  566. g_dwFanThrottleMaxMin = MAKELONG((short)0, (short)100);
  567. // Call will fail if monitor or adapter don't support DPMS.
  568. g_bVideoLowPowerSupported = SystemParametersInfo(SPI_GETLOWPOWERACTIVE,
  569. 0, &dummy, 0);
  570. if (!g_bVideoLowPowerSupported) {
  571. g_bVideoLowPowerSupported = SystemParametersInfo(SPI_GETPOWEROFFACTIVE,
  572. 0, &dummy, 0);
  573. }
  574. #ifdef WINNT
  575. //
  576. // Check to see if APM is present
  577. //
  578. pspc->ApmPresent = IsNtApmPresent(pspc);
  579. pspc->UpsPresent = IsUpsPresent(pspc);
  580. #endif
  581. return TRUE;
  582. }
  583. /*******************************************************************************
  584. *
  585. * SyncRegPPM
  586. *
  587. * DESCRIPTION:
  588. * Call down to the PPM to get the current power policies and write them
  589. * to the registry. This is done in case the PPM is out of sync with the
  590. * PowerCfg registry settings. Requested by JVert.
  591. *
  592. * PARAMETERS:
  593. *
  594. *******************************************************************************/
  595. VOID SyncRegPPM(VOID)
  596. {
  597. GLOBAL_POWER_POLICY gpp;
  598. POWER_POLICY pp;
  599. UINT uiID, uiFlags = 0;
  600. if (ReadGlobalPwrPolicy(&gpp)) {
  601. uiFlags = gpp.user.GlobalFlags;
  602. }
  603. if (GetActivePwrScheme(&uiID)) {
  604. // Get the current PPM settings.
  605. if (GetCurrentPowerPolicies(&gpp, &pp)) {
  606. SetActivePwrScheme(uiID, &gpp, &pp);
  607. }
  608. }
  609. gpp.user.GlobalFlags |= uiFlags;
  610. }