ReactOS 0.4.16-dev-1946-g52006dd
advanced.c File Reference
#include "powercfg.h"
Include dependency graph for advanced.c:

Go to the source code of this file.

Functions

static VOID SetSystrayPowerIconState (BOOL bEnabled)
 
static BOOL GetSystrayPowerIconState (VOID)
 
static VOID AddItem (HWND hDlgCtrl, INT ResourceId, LPARAM lParam, POWER_ACTION *lpAction)
 
static INT FindActionIndex (POWER_ACTION *lpAction, DWORD dwActionSize, POWER_ACTION poAction)
 
static BOOLEAN IsBatteryUsed (VOID)
 
POWER_ACTION GetPowerActionFromPolicy (POWER_ACTION_POLICY *Policy, PSYSTEM_POWER_CAPABILITIES spc, BOOL bIsLid)
 
VOID ShowCurrentPowerActionPolicy (HWND hDlgCtrl, POWER_ACTION *lpAction, DWORD dwActionSize, POWER_ACTION_POLICY *Policy, PSYSTEM_POWER_CAPABILITIES spc, BOOL bIsLid)
 
BOOLEAN SaveCurrentPowerActionPolicy (IN HWND hDlgCtrl, OUT POWER_ACTION_POLICY *Policy)
 
VOID ShowCurrentPowerActionPolicies (HWND hwndDlg, PSYSTEM_POWER_CAPABILITIES spc)
 
VOID Adv_InitDialog (HWND hwndDlg)
 
static VOID Adv_SaveData (HWND hwndDlg)
 
INT_PTR CALLBACK AdvancedDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 

Variables

static POWER_ACTION g_SystemBatteries [3]
 
static POWER_ACTION g_PowerButton [5]
 
static POWER_ACTION g_SleepButton [5]
 

Function Documentation

◆ AddItem()

static VOID AddItem ( HWND  hDlgCtrl,
INT  ResourceId,
LPARAM  lParam,
POWER_ACTION lpAction 
)
static

Definition at line 45 of file advanced.c.

46{
47 TCHAR szBuffer[MAX_PATH];
49
50 if (LoadString(hApplet, ResourceId, szBuffer, _countof(szBuffer)) < _countof(szBuffer))
51 {
52 Index = SendMessage(hDlgCtrl, CB_INSERTSTRING, -1, (LPARAM)szBuffer);
53 if (Index != CB_ERR)
54 {
56 lpAction[Index] = (POWER_ACTION)lParam;
57 }
58 }
59}
INT ResourceId
Definition: LoadImageGCC.c:72
LPARAM lParam
Definition: combotst.c:139
HINSTANCE hApplet
Definition: access.c:17
#define MAX_PATH
Definition: compat.h:34
LONG_PTR LPARAM
Definition: minwindef.h:175
LONG_PTR LRESULT
Definition: minwindef.h:176
UINT_PTR WPARAM
Definition: minwindef.h:174
POWER_ACTION
Definition: ntpoapi.h:122
#define _countof(array)
Definition: sndvol32.h:70
_In_ WDFCOLLECTION _In_ ULONG Index
#define CB_SETITEMDATA
Definition: winuser.h:1995
#define CB_ERR
Definition: winuser.h:2471
#define SendMessage
Definition: winuser.h:5954
#define LoadString
Definition: winuser.h:5930
#define CB_INSERTSTRING
Definition: winuser.h:1986
char TCHAR
Definition: xmlstorage.h:189

◆ Adv_InitDialog()

VOID Adv_InitDialog ( HWND  hwndDlg)

Definition at line 260 of file advanced.c.

262{
263 HWND hList1, hList2, hList3;
264 BOOLEAN bSuspend, bHibernate, bShutdown;
265 BOOL bEnabled;
267
268 bEnabled = GetSystrayPowerIconState();
269
270 if (bEnabled)
272 else
273 gGPP.user.GlobalFlags &= ~EnableSysTrayBatteryMeter;
274
275 CheckDlgButton(hwndDlg,
277 bEnabled ? BST_CHECKED : BST_UNCHECKED);
278 CheckDlgButton(hwndDlg,
281 CheckDlgButton(hwndDlg,
284
285 GetPwrCapabilities(&spc);
286
287 bSuspend = IS_PWR_SUSPEND_ALLOWED(&spc);
288 bHibernate = IS_PWR_HIBERNATE_ALLOWED(&spc);
290
291 hList1 = GetDlgItem(hwndDlg, IDC_LIDCLOSE);
292 SendMessage(hList1, CB_RESETCONTENT, 0, 0);
293
296 {
298
299 if (bSuspend)
301
302 if (bHibernate)
304 }
305 else
306 {
309 ShowWindow(hList1, SW_HIDE);
310 }
311
312 hList2 = GetDlgItem(hwndDlg, IDC_POWERBUTTON);
313 SendMessage(hList2, CB_RESETCONTENT, 0, 0);
314
316 if (spc.PowerButtonPresent)
317 {
320
321 if (bSuspend)
323
324 if (bHibernate)
326
327 if (bShutdown)
329 }
330 else
331 {
333 ShowWindow(hList2, SW_HIDE);
334 }
335
336 hList3 = GetDlgItem(hwndDlg, IDC_SLEEPBUTTON);
337 SendMessage(hList3, CB_RESETCONTENT, 0, 0);
338
340 if (spc.SleepButtonPresent)
341 {
344
345 if (bSuspend)
347
348 if (bHibernate)
350
351 if (bShutdown)
353 }
354 else
355 {
357 ShowWindow(hList3, SW_HIDE);
358 }
359
361 ShowCurrentPowerActionPolicies(hwndDlg, &spc);
362}
unsigned char BOOLEAN
static POWER_ACTION g_PowerButton[5]
Definition: advanced.c:14
static POWER_ACTION g_SleepButton[5]
Definition: advanced.c:15
VOID ShowCurrentPowerActionPolicies(HWND hwndDlg, PSYSTEM_POWER_CAPABILITIES spc)
Definition: advanced.c:207
static POWER_ACTION g_SystemBatteries[3]
Definition: advanced.c:13
static BOOL GetSystrayPowerIconState(VOID)
Definition: advanced.c:33
#define IDC_SLIDCLOSE
Definition: resource.h:141
#define IDS_PowerActionWarmEject
Definition: resource.h:70
#define IDS_PowerActionHibernate
Definition: resource.h:66
#define IDC_VIDEODIMDISPLAY
Definition: resource.h:140
#define IDC_SPOWERBUTTON
Definition: resource.h:143
#define IDC_SLEEPBUTTON
Definition: resource.h:146
#define IDS_PowerActionNone1
Definition: resource.h:63
#define IDS_PowerActionShutdown
Definition: resource.h:67
#define IDC_PASSWORDLOGON
Definition: resource.h:139
#define IDC_POWERBUTTON
Definition: resource.h:144
#define IDS_PowerActionSleep
Definition: resource.h:65
#define IDC_SYSTRAYBATTERYMETER
Definition: resource.h:138
#define IDC_SSLEEPBUTTON
Definition: resource.h:145
#define IDC_LIDCLOSE
Definition: resource.h:142
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ZeroMemory
Definition: minwinbase.h:31
#define IS_PWR_SUSPEND_ALLOWED(PowerCaps)
Definition: potypes.h:63
#define IS_PWR_HIBERNATE_ALLOWED(PowerCaps)
Definition: potypes.h:70
#define IS_PWR_POWEROFF_ALLOWED(PowerCaps)
Definition: potypes.h:77
@ PowerActionNone
Definition: ntpoapi.h:123
@ PowerActionHibernate
Definition: ntpoapi.h:126
@ PowerActionShutdown
Definition: ntpoapi.h:127
@ PowerActionWarmEject
Definition: ntpoapi.h:130
@ PowerActionSleep
Definition: ntpoapi.h:125
GLOBAL_POWER_POLICY gGPP
Definition: powercfg.c:16
BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
Definition: powrprof.c:582
BOOLEAN WINAPI ReadGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
Definition: powrprof.c:857
#define EnableVideoDimDisplay
Definition: powrprof.h:36
#define EnablePasswordLogon
Definition: powrprof.h:34
#define EnableSysTrayBatteryMeter
Definition: powrprof.h:32
BOOLEAN SystemBatteriesPresent
Definition: ntpoapi.h:374
GLOBAL_USER_POWER_POLICY user
Definition: powrprof.h:60
volatile BOOL bShutdown
Definition: tcpsvcs.c:16
#define AddItem
Definition: userenv.h:209
#define SW_HIDE
Definition: winuser.h:779
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define BST_UNCHECKED
Definition: winuser.h:199
#define CB_RESETCONTENT
Definition: winuser.h:1988
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define BST_CHECKED
Definition: winuser.h:197

Referenced by AdvancedDlgProc().

◆ Adv_SaveData()

static VOID Adv_SaveData ( HWND  hwndDlg)
static

Definition at line 365 of file advanced.c.

366{
367 BOOL bSystrayBatteryMeter;
368 BOOL bPasswordLogon;
369 BOOL bVideoDimDisplay;
370
371 bSystrayBatteryMeter =
373
374 bPasswordLogon =
376
377 bVideoDimDisplay =
379
380 if (bSystrayBatteryMeter)
381 {
383 {
385 }
386 }
387 else
388 {
390 {
392 }
393 }
394
395 if (bPasswordLogon)
396 {
398 {
400 }
401 }
402 else
403 {
405 {
407 }
408 }
409
410 if (bVideoDimDisplay)
411 {
413 {
415 }
416 }
417 else
418 {
420 {
422 }
423 }
424
425 if (!IsBatteryUsed())
426 {
427#if 0
429#endif
432 }
433 else
434 {
435#if 0
439#endif
440 }
441
443 {
444 MessageBox(hwndDlg, L"WriteGlobalPwrPolicy failed", NULL, MB_OK);
445 }
446
447 SetSystrayPowerIconState(bSystrayBatteryMeter);
448
449// Adv_InitDialog(hwndDlg);
450}
#define NULL
Definition: types.h:112
BOOLEAN SaveCurrentPowerActionPolicy(IN HWND hDlgCtrl, OUT POWER_ACTION_POLICY *Policy)
Definition: advanced.c:157
static BOOLEAN IsBatteryUsed(VOID)
Definition: advanced.c:76
static VOID SetSystrayPowerIconState(BOOL bEnabled)
Definition: advanced.c:20
#define L(x)
Definition: resources.c:13
BOOLEAN WINAPI WriteGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
Definition: powrprof.c:1026
POWER_ACTION_POLICY PowerButtonDc
Definition: powrprof.h:49
POWER_ACTION_POLICY LidCloseDc
Definition: powrprof.h:53
POWER_ACTION_POLICY SleepButtonDc
Definition: powrprof.h:51
POWER_ACTION_POLICY PowerButtonAc
Definition: powrprof.h:48
POWER_ACTION_POLICY SleepButtonAc
Definition: powrprof.h:50
POWER_ACTION_POLICY LidCloseAc
Definition: powrprof.h:52
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define MB_OK
Definition: winuser.h:801
#define MessageBox
Definition: winuser.h:5933

Referenced by AdvancedDlgProc().

◆ AdvancedDlgProc()

INT_PTR CALLBACK AdvancedDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 454 of file advanced.c.

458{
459 switch (uMsg)
460 {
461 case WM_INITDIALOG:
462 Adv_InitDialog(hwndDlg);
463 return TRUE;
464
465 case WM_COMMAND:
466 switch (LOWORD(wParam))
467 {
471 if (HIWORD(wParam) == BN_CLICKED)
472 {
473 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
474 }
475 break;
476
477 case IDC_LIDCLOSE:
478 case IDC_POWERBUTTON:
479 case IDC_SLEEPBUTTON:
481 {
482 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
483 }
484 break;
485 }
486 break;
487
488 case WM_NOTIFY:
489 switch (((LPNMHDR)lParam)->code)
490 {
491 case PSN_APPLY:
492 Adv_SaveData(hwndDlg);
493 return TRUE;
494
495 case PSN_SETACTIVE:
496 Adv_InitDialog(hwndDlg);
497 return TRUE;
498 }
499 break;
500 }
501
502 return FALSE;
503}
WPARAM wParam
Definition: combotst.c:138
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
VOID Adv_InitDialog(HWND hwndDlg)
Definition: advanced.c:260
static VOID Adv_SaveData(HWND hwndDlg)
Definition: advanced.c:365
#define LOWORD(l)
Definition: pedump.c:82
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
#define PSN_APPLY
Definition: prsht.h:117
#define PSN_SETACTIVE
Definition: prsht.h:115
#define WM_NOTIFY
Definition: richedit.h:61
Definition: inflate.c:139
#define HIWORD(l)
Definition: typedefs.h:247
#define WM_COMMAND
Definition: winuser.h:1768
#define WM_INITDIALOG
Definition: winuser.h:1767
#define CBN_SELCHANGE
Definition: winuser.h:2008
HWND WINAPI GetParent(_In_ HWND)
#define BN_CLICKED
Definition: winuser.h:1954

◆ FindActionIndex()

static INT FindActionIndex ( POWER_ACTION lpAction,
DWORD  dwActionSize,
POWER_ACTION  poAction 
)
static

Definition at line 62 of file advanced.c.

63{
64 INT Index;
65
66 for (Index = 0; Index < (INT)dwActionSize; Index++)
67 {
68 if (lpAction[Index] == poAction)
69 return Index;
70 }
71
72 return -1;
73}
#define INT
Definition: polytest.cpp:20
int32_t INT
Definition: typedefs.h:58

Referenced by ShowCurrentPowerActionPolicy().

◆ GetPowerActionFromPolicy()

POWER_ACTION GetPowerActionFromPolicy ( POWER_ACTION_POLICY Policy,
PSYSTEM_POWER_CAPABILITIES  spc,
BOOL  bIsLid 
)

Definition at line 86 of file advanced.c.

90{
92 /*
93
94 TCHAR szBuffer[MAX_PATH];
95
96 // Note: Windows XP SP2+ does not return the PowerAction code
97 // for PowerActionWarmEject + PowerActionShutdown but sets it
98 // to PowerActionNone and sets the Flags & EventCode
99
100 _stprintf(szBuffer, L"Action: %x EventCode %x Flags %x",Policy->Action, Policy->EventCode, Policy->Flags);
101 MessageBoxW(NULL, szBuffer, NULL, MB_OK);
102
103 */
104
105 if (Policy->Action == PowerActionNone)
106 {
108 {
109 if (Policy->EventCode == POWER_FORCE_TRIGGER_RESET)
110 poAction = PowerActionNone;
111 else if (Policy->EventCode == POWER_USER_NOTIFY_BUTTON)
112 poAction = PowerActionWarmEject;
113 else if (Policy->EventCode == POWER_USER_NOTIFY_SHUTDOWN)
114 poAction = PowerActionShutdown;
115 }
116 }
117 else
118 {
119 poAction = Policy->Action;
120 if ((poAction == PowerActionHibernate) && !IS_PWR_HIBERNATE_ALLOWED(spc))
121 poAction = PowerActionSleep;
122 if ((poAction == PowerActionSleep) && !IS_PWR_SUSPEND_ALLOWED(spc))
123 {
124 if (bIsLid)
125 poAction = PowerActionNone;
126 else
127 poAction = PowerActionShutdown;
128 }
129 }
130
131 return poAction;
132}
#define POWER_ACTION_UI_ALLOWED
Definition: ntpoapi.h:416
#define POWER_USER_NOTIFY_BUTTON
Definition: ntpoapi.h:427
#define POWER_FORCE_TRIGGER_RESET
Definition: ntpoapi.h:429
#define POWER_ACTION_QUERY_ALLOWED
Definition: ntpoapi.h:415
#define POWER_USER_NOTIFY_SHUTDOWN
Definition: ntpoapi.h:428
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY Policy
Definition: wdfinterrupt.h:653

Referenced by ShowCurrentPowerActionPolicy().

◆ GetSystrayPowerIconState()

static BOOL GetSystrayPowerIconState ( VOID  )
static

Definition at line 33 of file advanced.c.

34{
35 HWND hwndTaskBar;
36
37 hwndTaskBar = FindWindowW(L"SystemTray_Main", NULL);
38 if (hwndTaskBar == NULL)
39 return FALSE;
40
41 return (BOOL)SendMessageW(hwndTaskBar, WM_USER + 221, 1, 0);
42}
#define WM_USER
Definition: winuser.h:1923
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by Adv_InitDialog().

◆ IsBatteryUsed()

static BOOLEAN IsBatteryUsed ( VOID  )
static

Definition at line 76 of file advanced.c.

77{
79
80 if (CallNtPowerInformation(SystemBatteryState, NULL, 0, &sbs, sizeof(sbs)) == STATUS_SUCCESS)
81 return (sbs.BatteryPresent && !sbs.AcOnLine);
82 return FALSE;
83}
@ SystemBatteryState
Definition: ntpoapi.h:72
NTSTATUS WINAPI CallNtPowerInformation(POWER_INFORMATION_LEVEL InformationLevel, PVOID lpInputBuffer, ULONG nInputBufferSize, PVOID lpOutputBuffer, ULONG nOutputBufferSize)
Definition: powrprof.c:283
#define STATUS_SUCCESS
Definition: shellext.h:65
BOOLEAN BatteryPresent
Definition: ntpoapi.h:386

Referenced by Adv_SaveData(), and ShowCurrentPowerActionPolicies().

◆ SaveCurrentPowerActionPolicy()

BOOLEAN SaveCurrentPowerActionPolicy ( IN HWND  hDlgCtrl,
OUT POWER_ACTION_POLICY Policy 
)

Definition at line 157 of file advanced.c.

159{
161 LRESULT ItemData;
162
163 Index = SendMessage(hDlgCtrl, CB_GETCURSEL, 0, 0);
164 if (Index == CB_ERR)
165 return FALSE;
166
167 ItemData = SendMessage(hDlgCtrl, CB_GETITEMDATA, (WPARAM)Index, 0);
168 if (ItemData == CB_ERR)
169 return FALSE;
170
171 switch(ItemData)
172 {
173 case PowerActionNone:
174 Policy->Action = PowerActionNone;
176 break;
177
179 Policy->Action = PowerActionNone;
180 Policy->EventCode = POWER_USER_NOTIFY_BUTTON;
181 break;
182
184 Policy->Action = PowerActionNone;
186 break;
187
188 case PowerActionSleep:
190 Policy->Action = (POWER_ACTION)ItemData;
191 Policy->EventCode = 0;
192 break;
193
194 default:
195 return FALSE;
196 }
197
199
200 return TRUE;
201}
#define CB_GETITEMDATA
Definition: winuser.h:1979
#define CB_GETCURSEL
Definition: winuser.h:1972

Referenced by Adv_SaveData().

◆ SetSystrayPowerIconState()

static VOID SetSystrayPowerIconState ( BOOL  bEnabled)
static

Definition at line 20 of file advanced.c.

21{
22 HWND hwndTaskBar;
23
24 hwndTaskBar = FindWindowW(L"SystemTray_Main", NULL);
25 if (hwndTaskBar == NULL)
26 return;
27
28 SendMessageW(hwndTaskBar, WM_USER + 220, 1, bEnabled);
29}

Referenced by Adv_SaveData().

◆ ShowCurrentPowerActionPolicies()

VOID ShowCurrentPowerActionPolicies ( HWND  hwndDlg,
PSYSTEM_POWER_CAPABILITIES  spc 
)

Definition at line 207 of file advanced.c.

210{
211 if (!IsBatteryUsed())
212 {
215 sizeof(g_SystemBatteries) / sizeof(POWER_ACTION),
217 spc,
218 TRUE);
219
222 sizeof(g_PowerButton) / sizeof(POWER_ACTION),
224 spc,
225 FALSE);
226
229 sizeof(g_SleepButton) / sizeof(POWER_ACTION),
231 spc,
232 FALSE);
233 }
234 else
235 {
238 sizeof(g_SystemBatteries) / sizeof(POWER_ACTION),
240 spc,
241 TRUE);
242
245 sizeof(g_PowerButton) / sizeof(POWER_ACTION),
247 spc,
248 FALSE);
249
252 sizeof(g_SleepButton) / sizeof(POWER_ACTION),
254 spc,
255 FALSE);
256 }
257}
VOID ShowCurrentPowerActionPolicy(HWND hDlgCtrl, POWER_ACTION *lpAction, DWORD dwActionSize, POWER_ACTION_POLICY *Policy, PSYSTEM_POWER_CAPABILITIES spc, BOOL bIsLid)
Definition: advanced.c:135

Referenced by Adv_InitDialog().

◆ ShowCurrentPowerActionPolicy()

VOID ShowCurrentPowerActionPolicy ( HWND  hDlgCtrl,
POWER_ACTION lpAction,
DWORD  dwActionSize,
POWER_ACTION_POLICY Policy,
PSYSTEM_POWER_CAPABILITIES  spc,
BOOL  bIsLid 
)

Definition at line 135 of file advanced.c.

141{
142 int poActionIndex;
143 POWER_ACTION poAction;
144
145 poAction = GetPowerActionFromPolicy(Policy, spc, bIsLid);
146 poActionIndex = FindActionIndex(lpAction, dwActionSize, poAction);
147
148 if (poActionIndex < 0)
149 {
150 return;
151 }
152
153 SendMessage(hDlgCtrl, CB_SETCURSEL, (WPARAM)poActionIndex, (LPARAM)0);
154}
POWER_ACTION GetPowerActionFromPolicy(POWER_ACTION_POLICY *Policy, PSYSTEM_POWER_CAPABILITIES spc, BOOL bIsLid)
Definition: advanced.c:86
static INT FindActionIndex(POWER_ACTION *lpAction, DWORD dwActionSize, POWER_ACTION poAction)
Definition: advanced.c:62
#define CB_SETCURSEL
Definition: winuser.h:1990

Referenced by ShowCurrentPowerActionPolicies().

Variable Documentation

◆ g_PowerButton

POWER_ACTION g_PowerButton[5]
static

Definition at line 14 of file advanced.c.

Referenced by Adv_InitDialog(), and ShowCurrentPowerActionPolicies().

◆ g_SleepButton

POWER_ACTION g_SleepButton[5]
static

Definition at line 15 of file advanced.c.

Referenced by Adv_InitDialog(), and ShowCurrentPowerActionPolicies().

◆ g_SystemBatteries

POWER_ACTION g_SystemBatteries[3]
static

Definition at line 13 of file advanced.c.

Referenced by Adv_InitDialog(), and ShowCurrentPowerActionPolicies().