ReactOS 0.4.16-dev-329-g9223134
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 46 of file advanced.c.

47{
48 TCHAR szBuffer[MAX_PATH];
50
52 {
53 Index = SendMessage(hDlgCtrl, CB_INSERTSTRING, -1, (LPARAM)szBuffer);
54 if (Index != CB_ERR)
55 {
57 lpAction[Index] = (POWER_ACTION)lParam;
58 }
59 }
60}
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
POWER_ACTION
Definition: ntpoapi.h:122
_In_ WDFCOLLECTION _In_ ULONG Index
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define CB_SETITEMDATA
Definition: winuser.h:1969
#define CB_ERR
Definition: winuser.h:2438
#define SendMessage
Definition: winuser.h:5855
#define LoadString
Definition: winuser.h:5831
#define CB_INSERTSTRING
Definition: winuser.h:1960
char TCHAR
Definition: xmlstorage.h:189

◆ Adv_InitDialog()

VOID Adv_InitDialog ( HWND  hwndDlg)

Definition at line 278 of file advanced.c.

280{
281 HWND hList1;
282 HWND hList2;
283 HWND hList3;
284
285 BOOLEAN bSuspend = FALSE;
286 BOOLEAN bHibernate;
288 BOOL bEnabled;
289
291
292 bEnabled = GetSystrayPowerIconState();
293
294 if (bEnabled)
296 else
297 gGPP.user.GlobalFlags &= ~EnableSysTrayBatteryMeter;
298
299 CheckDlgButton(hwndDlg,
301 bEnabled ? BST_CHECKED : BST_UNCHECKED);
302 CheckDlgButton(hwndDlg,
305 CheckDlgButton(hwndDlg,
308
309 GetPwrCapabilities(&spc);
310
311 if (spc.SystemS1 || spc.SystemS2 || spc.SystemS3)
312 bSuspend=TRUE;
313
314 bHibernate = spc.HiberFilePresent;
315 bShutdown = spc.SystemS5;
316
317 hList1 = GetDlgItem(hwndDlg, IDC_LIDCLOSE);
318 SendMessage(hList1, CB_RESETCONTENT, 0, 0);
319
322 {
324
325 if (bSuspend)
326 {
328 }
329
330 if (bHibernate)
331 {
333 }
334 }
335 else
336 {
339 ShowWindow(hList1, FALSE);
340 }
341
342 hList2 = GetDlgItem(hwndDlg, IDC_POWERBUTTON);
343 SendMessage(hList2, CB_RESETCONTENT, 0, 0);
344
345 memset(g_PowerButton, 0x0, sizeof(g_PowerButton));
346 if (spc.PowerButtonPresent)
347 {
350
351 if (bSuspend)
352 {
354 }
355
356 if (bHibernate)
357 {
359 }
360
361 if (bShutdown)
362 {
364 }
365 }
366 else
367 {
369 ShowWindow(hList2, FALSE);
370 }
371
372 hList3 = GetDlgItem(hwndDlg, IDC_SLEEPBUTTON);
373 SendMessage(hList3, CB_RESETCONTENT, 0, 0);
374 memset(g_SleepButton, 0x0, sizeof(g_SleepButton));
375
376 if (spc.SleepButtonPresent)
377 {
380
381 if (bSuspend)
382 {
384 }
385
386 if (bHibernate)
387 {
389 }
390
391 if (bShutdown)
392 {
394 }
395 }
396 else
397 {
399 ShowWindow(hList3, FALSE);
400 }
401
403 {
404 ShowCurrentPowerActionPolicies(hwndDlg, &spc);
405 }
406}
unsigned char BOOLEAN
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static POWER_ACTION g_PowerButton[5]
Definition: advanced.c:15
static POWER_ACTION g_SleepButton[5]
Definition: advanced.c:16
VOID ShowCurrentPowerActionPolicies(HWND hwndDlg, PSYSTEM_POWER_CAPABILITIES spc)
Definition: advanced.c:225
static POWER_ACTION g_SystemBatteries[3]
Definition: advanced.c:14
static BOOL GetSystrayPowerIconState(VOID)
Definition: advanced.c:34
#define IDC_SLIDCLOSE
Definition: resource.h:98
#define IDS_PowerActionWarmEject
Definition: resource.h:30
#define IDS_PowerActionHibernate
Definition: resource.h:26
#define IDC_VIDEODIMDISPLAY
Definition: resource.h:97
#define IDC_SPOWERBUTTON
Definition: resource.h:100
#define IDC_SLEEPBUTTON
Definition: resource.h:103
#define IDS_PowerActionNone1
Definition: resource.h:23
#define IDS_PowerActionShutdown
Definition: resource.h:27
#define IDC_PASSWORDLOGON
Definition: resource.h:96
#define IDC_POWERBUTTON
Definition: resource.h:101
#define IDS_PowerActionSleep
Definition: resource.h:25
#define IDC_SYSTRAYBATTERYMETER
Definition: resource.h:95
#define IDC_SSLEEPBUTTON
Definition: resource.h:102
#define IDC_LIDCLOSE
Definition: resource.h:99
unsigned int BOOL
Definition: ntddk_ex.h:94
@ 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:23
BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
Definition: powrprof.c:358
BOOLEAN WINAPI ReadGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
Definition: powrprof.c:521
#define EnableVideoDimDisplay
Definition: powrprof.h:19
#define EnablePasswordLogon
Definition: powrprof.h:16
#define EnableSysTrayBatteryMeter
Definition: powrprof.h:17
#define memset(x, y, z)
Definition: compat.h:39
BOOLEAN SystemBatteriesPresent
Definition: ntpoapi.h:374
GLOBAL_USER_POWER_POLICY user
Definition: powrprof.h:42
volatile BOOL bShutdown
Definition: tcpsvcs.c:16
#define AddItem
Definition: userenv.h:209
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:1962
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 409 of file advanced.c.

410{
411 BOOL bSystrayBatteryMeter;
412 BOOL bPasswordLogon;
413 BOOL bVideoDimDisplay;
414
415 bSystrayBatteryMeter =
417
418 bPasswordLogon =
420
421 bVideoDimDisplay =
423
424 if (bSystrayBatteryMeter)
425 {
427 {
429 }
430 }
431 else
432 {
434 {
436 }
437 }
438
439 if (bPasswordLogon)
440 {
442 {
444 }
445 }
446 else
447 {
449 {
451 }
452 }
453
454 if (bVideoDimDisplay)
455 {
457 {
459 }
460 }
461 else
462 {
464 {
466 }
467 }
468
469 if (!IsBatteryUsed())
470 {
471#if 0
473#endif
476 }
477 else
478 {
479#if 0
483#endif
484 }
485
487 {
488 MessageBox(hwndDlg, L"WriteGlobalPwrPolicy failed", NULL, MB_OK);
489 }
490
491 SetSystrayPowerIconState(bSystrayBatteryMeter);
492
493// Adv_InitDialog(hwndDlg);
494}
#define NULL
Definition: types.h:112
BOOLEAN SaveCurrentPowerActionPolicy(IN HWND hDlgCtrl, OUT POWER_ACTION_POLICY *Policy)
Definition: advanced.c:175
static BOOLEAN IsBatteryUsed(VOID)
Definition: advanced.c:77
static VOID SetSystrayPowerIconState(BOOL bEnabled)
Definition: advanced.c:21
#define L(x)
Definition: ntvdm.h:50
BOOLEAN WINAPI WriteGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
Definition: powrprof.c:690
POWER_ACTION_POLICY PowerButtonDc
Definition: powrprof.h:33
POWER_ACTION_POLICY LidCloseDc
Definition: powrprof.h:37
POWER_ACTION_POLICY SleepButtonDc
Definition: powrprof.h:35
POWER_ACTION_POLICY PowerButtonAc
Definition: powrprof.h:32
POWER_ACTION_POLICY SleepButtonAc
Definition: powrprof.h:34
POWER_ACTION_POLICY LidCloseAc
Definition: powrprof.h:36
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define MB_OK
Definition: winuser.h:793
#define MessageBox
Definition: winuser.h:5834

Referenced by AdvancedDlgProc().

◆ AdvancedDlgProc()

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

Definition at line 498 of file advanced.c.

502{
503 switch (uMsg)
504 {
505 case WM_INITDIALOG:
506 Adv_InitDialog(hwndDlg);
507 return TRUE;
508
509 case WM_COMMAND:
510 switch (LOWORD(wParam))
511 {
515 if (HIWORD(wParam) == BN_CLICKED)
516 {
517 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
518 }
519 break;
520
521 case IDC_LIDCLOSE:
522 case IDC_POWERBUTTON:
523 case IDC_SLEEPBUTTON:
525 {
526 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
527 }
528 break;
529 }
530 break;
531
532 case WM_NOTIFY:
533 switch (((LPNMHDR)lParam)->code)
534 {
535 case PSN_APPLY:
536 Adv_SaveData(hwndDlg);
537 return TRUE;
538
539 case PSN_SETACTIVE:
540 Adv_InitDialog(hwndDlg);
541 return TRUE;
542 }
543 break;
544 }
545
546 return FALSE;
547}
WPARAM wParam
Definition: combotst.c:138
VOID Adv_InitDialog(HWND hwndDlg)
Definition: advanced.c:278
static VOID Adv_SaveData(HWND hwndDlg)
Definition: advanced.c:409
#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:1743
#define WM_INITDIALOG
Definition: winuser.h:1742
#define CBN_SELCHANGE
Definition: winuser.h:1982
HWND WINAPI GetParent(_In_ HWND)
#define BN_CLICKED
Definition: winuser.h:1928

◆ FindActionIndex()

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

Definition at line 63 of file advanced.c.

64{
65 INT Index;
66
67 for (Index = 0; Index < (INT)dwActionSize; Index++)
68 {
69 if (lpAction[Index] == poAction)
70 return Index;
71 }
72
73 return -1;
74}
#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 97 of file advanced.c.

101{
102 POWER_ACTION poAction = PowerActionNone;
103 /*
104
105 TCHAR szBuffer[MAX_PATH];
106
107 // Note: Windows XP SP2+ does not return the PowerAction code
108 // for PowerActionWarmEject + PowerActionShutdown but sets it
109 // to PowerActionNone and sets the Flags & EventCode
110
111
112 _stprintf(szBuffer, L"Action: %x EventCode %x Flags %x",Policy->Action, Policy->EventCode, Policy->Flags);
113 MessageBoxW(NULL, szBuffer, NULL, MB_OK);
114
115 */
116
117 if (Policy->Action == PowerActionNone)
118 {
120 {
121 if (Policy->EventCode == POWER_FORCE_TRIGGER_RESET)
122 {
123 poAction = PowerActionNone;
124 }
125 else if (Policy->EventCode == POWER_USER_NOTIFY_BUTTON)
126 {
127 poAction = PowerActionWarmEject;
128 }
129 else if (Policy->EventCode == POWER_USER_NOTIFY_SHUTDOWN)
130 {
131 poAction = PowerActionShutdown;
132 }
133 }
134 }
135 else
136 {
137 poAction = Policy->Action;
138 if ((poAction == PowerActionHibernate) && !(spc->SystemS4 && spc->HiberFilePresent))
139 poAction = PowerActionSleep;
140 if ((poAction == PowerActionSleep) && !(spc->SystemS1 || spc->SystemS2 || spc->SystemS3))
141 {
142 if (bIsLid)
143 poAction = PowerActionNone;
144 else
145 poAction = PowerActionShutdown;
146 }
147 }
148
149 return poAction;
150}
#define POWER_ACTION_UI_ALLOWED
Definition: ntpoapi.h:415
#define POWER_USER_NOTIFY_BUTTON
Definition: ntpoapi.h:426
#define POWER_FORCE_TRIGGER_RESET
Definition: ntpoapi.h:428
#define POWER_ACTION_QUERY_ALLOWED
Definition: ntpoapi.h:414
#define POWER_USER_NOTIFY_SHUTDOWN
Definition: ntpoapi.h:427
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY Policy
Definition: wdfinterrupt.h:653

Referenced by ShowCurrentPowerActionPolicy().

◆ GetSystrayPowerIconState()

static BOOL GetSystrayPowerIconState ( VOID  )
static

Definition at line 34 of file advanced.c.

35{
36 HWND hwndTaskBar;
37
38 hwndTaskBar = FindWindowW(L"SystemTray_Main", NULL);
39 if (hwndTaskBar == NULL)
40 return FALSE;
41
42 return (BOOL)SendMessageW(hwndTaskBar, WM_USER + 221, 1, 0);
43}
#define WM_USER
Definition: winuser.h:1898
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 77 of file advanced.c.

78{
80
82 {
83 if (sbs.BatteryPresent)
84 {
85 if (sbs.AcOnLine)
86 {
87 return FALSE;
88 }
89 return TRUE;
90 }
91 }
92
93 return FALSE;
94}
@ SystemBatteryState
Definition: ntpoapi.h:72
NTSTATUS WINAPI CallNtPowerInformation(POWER_INFORMATION_LEVEL InformationLevel, PVOID lpInputBuffer, ULONG nInputBufferSize, PVOID lpOutputBuffer, ULONG nOutputBufferSize)
Definition: powrprof.c:59
#define STATUS_SUCCESS
Definition: shellext.h:65
BOOLEAN BatteryPresent
Definition: ntpoapi.h:386
uint32_t ULONG
Definition: typedefs.h:59

Referenced by Adv_SaveData(), and ShowCurrentPowerActionPolicies().

◆ SaveCurrentPowerActionPolicy()

BOOLEAN SaveCurrentPowerActionPolicy ( IN HWND  hDlgCtrl,
OUT POWER_ACTION_POLICY Policy 
)

Definition at line 175 of file advanced.c.

177{
179 LRESULT ItemData;
180
181 Index = SendMessage(hDlgCtrl, CB_GETCURSEL, 0, 0);
182 if (Index == CB_ERR)
183 return FALSE;
184
185 ItemData = SendMessage(hDlgCtrl, CB_GETITEMDATA, (WPARAM)Index, 0);
186 if (ItemData == CB_ERR)
187 return FALSE;
188
189 switch(ItemData)
190 {
191 case PowerActionNone:
192 Policy->Action = PowerActionNone;
194 break;
195
197 Policy->Action = PowerActionNone;
198 Policy->EventCode = POWER_USER_NOTIFY_BUTTON;
199 break;
200
202 Policy->Action = PowerActionNone;
204 break;
205
206 case PowerActionSleep:
208 Policy->Action = (POWER_ACTION)ItemData;
209 Policy->EventCode = 0;
210 break;
211
212 default:
213 return FALSE;
214 }
215
217
218 return TRUE;
219}
#define CB_GETITEMDATA
Definition: winuser.h:1953
#define CB_GETCURSEL
Definition: winuser.h:1946

Referenced by Adv_SaveData().

◆ SetSystrayPowerIconState()

static VOID SetSystrayPowerIconState ( BOOL  bEnabled)
static

Definition at line 21 of file advanced.c.

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

Referenced by Adv_SaveData().

◆ ShowCurrentPowerActionPolicies()

VOID ShowCurrentPowerActionPolicies ( HWND  hwndDlg,
PSYSTEM_POWER_CAPABILITIES  spc 
)

Definition at line 225 of file advanced.c.

228{
229 if (!IsBatteryUsed())
230 {
233 sizeof(g_SystemBatteries) / sizeof(POWER_ACTION),
235 spc,
236 TRUE);
237
240 sizeof(g_PowerButton) / sizeof(POWER_ACTION),
242 spc,
243 FALSE);
244
247 sizeof(g_SleepButton) / sizeof(POWER_ACTION),
249 spc,
250 FALSE);
251 }
252 else
253 {
256 sizeof(g_SystemBatteries) / sizeof(POWER_ACTION),
258 spc,
259 TRUE);
260
263 sizeof(g_PowerButton) / sizeof(POWER_ACTION),
265 spc,
266 FALSE);
267
270 sizeof(g_SleepButton) / sizeof(POWER_ACTION),
272 spc,
273 FALSE);
274 }
275}
VOID ShowCurrentPowerActionPolicy(HWND hDlgCtrl, POWER_ACTION *lpAction, DWORD dwActionSize, POWER_ACTION_POLICY *Policy, PSYSTEM_POWER_CAPABILITIES spc, BOOL bIsLid)
Definition: advanced.c:153

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 153 of file advanced.c.

159{
160 int poActionIndex;
161 POWER_ACTION poAction;
162
163 poAction = GetPowerActionFromPolicy(Policy, spc, bIsLid);
164 poActionIndex = FindActionIndex(lpAction, dwActionSize, poAction);
165
166 if (poActionIndex < 0)
167 {
168 return;
169 }
170
171 SendMessage(hDlgCtrl, CB_SETCURSEL, (WPARAM)poActionIndex, (LPARAM)0);
172}
POWER_ACTION GetPowerActionFromPolicy(POWER_ACTION_POLICY *Policy, PSYSTEM_POWER_CAPABILITIES spc, BOOL bIsLid)
Definition: advanced.c:97
static INT FindActionIndex(POWER_ACTION *lpAction, DWORD dwActionSize, POWER_ACTION poAction)
Definition: advanced.c:63
#define CB_SETCURSEL
Definition: winuser.h:1964

Referenced by ShowCurrentPowerActionPolicies().

Variable Documentation

◆ g_PowerButton

POWER_ACTION g_PowerButton[5]
static

Definition at line 15 of file advanced.c.

Referenced by Adv_InitDialog(), and ShowCurrentPowerActionPolicies().

◆ g_SleepButton

POWER_ACTION g_SleepButton[5]
static

Definition at line 16 of file advanced.c.

Referenced by Adv_InitDialog(), and ShowCurrentPowerActionPolicies().

◆ g_SystemBatteries

POWER_ACTION g_SystemBatteries[3]
static

Definition at line 14 of file advanced.c.

Referenced by Adv_InitDialog(), and ShowCurrentPowerActionPolicies().