ReactOS 0.4.15-dev-7788-g1ad9096
advanced.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Power Configuration Applet
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/powercfg/advanced.c
5 * PURPOSE: advanced tab 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
17
18
19static
20VOID
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}
31
32static
33BOOL
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}
44
45static VOID
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}
61
62static INT
63FindActionIndex(POWER_ACTION * lpAction, DWORD dwActionSize, POWER_ACTION poAction)
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}
75
76static BOOLEAN
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}
95
100 BOOL bIsLid)
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}
151
152VOID
154 POWER_ACTION *lpAction,
155 DWORD dwActionSize,
158 BOOL bIsLid)
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}
173
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}
220
221
222//-------------------------------------------------------------------
223
224VOID
226 HWND hwndDlg,
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}
276
277VOID
279 HWND hwndDlg)
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}
407
408static VOID
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}
495
496/* Property page dialog callback */
499 UINT uMsg,
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}
INT ResourceId
unsigned char BOOLEAN
INT_PTR CALLBACK AdvancedDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: advanced.c:225
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HINSTANCE hApplet
Definition: access.c:17
static POWER_ACTION g_PowerButton[5]
Definition: advanced.c:15
POWER_ACTION GetPowerActionFromPolicy(POWER_ACTION_POLICY *Policy, PSYSTEM_POWER_CAPABILITIES spc, BOOL bIsLid)
Definition: advanced.c:97
VOID Adv_InitDialog(HWND hwndDlg)
Definition: advanced.c:278
VOID ShowCurrentPowerActionPolicy(HWND hDlgCtrl, POWER_ACTION *lpAction, DWORD dwActionSize, POWER_ACTION_POLICY *Policy, PSYSTEM_POWER_CAPABILITIES spc, BOOL bIsLid)
Definition: advanced.c:153
static VOID Adv_SaveData(HWND hwndDlg)
Definition: advanced.c:409
BOOLEAN SaveCurrentPowerActionPolicy(IN HWND hDlgCtrl, OUT POWER_ACTION_POLICY *Policy)
Definition: advanced.c:175
static POWER_ACTION g_SleepButton[5]
Definition: advanced.c:16
static BOOLEAN IsBatteryUsed(VOID)
Definition: advanced.c:77
static INT FindActionIndex(POWER_ACTION *lpAction, DWORD dwActionSize, POWER_ACTION poAction)
Definition: advanced.c:63
VOID ShowCurrentPowerActionPolicies(HWND hwndDlg, PSYSTEM_POWER_CAPABILITIES spc)
Definition: advanced.c:225
static VOID SetSystrayPowerIconState(BOOL bEnabled)
Definition: advanced.c:21
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
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned int UINT
Definition: ndis.h:50
#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
POWER_ACTION
Definition: ntpoapi.h:122
@ 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
#define POWER_USER_NOTIFY_SHUTDOWN
Definition: ntpoapi.h:427
@ SystemBatteryState
Definition: ntpoapi.h:72
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define INT
Definition: polytest.cpp:20
GLOBAL_POWER_POLICY gGPP
Definition: powercfg.c:23
BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
Definition: powrprof.c:358
NTSTATUS WINAPI CallNtPowerInformation(POWER_INFORMATION_LEVEL InformationLevel, PVOID lpInputBuffer, ULONG nInputBufferSize, PVOID lpOutputBuffer, ULONG nOutputBufferSize)
Definition: powrprof.c:59
BOOLEAN WINAPI WriteGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
Definition: powrprof.c:690
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 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
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
BOOLEAN BatteryPresent
Definition: ntpoapi.h:386
BOOLEAN SystemBatteriesPresent
Definition: ntpoapi.h:374
GLOBAL_USER_POWER_POLICY user
Definition: powrprof.h:42
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
Definition: inflate.c:139
volatile BOOL bShutdown
Definition: tcpsvcs.c:16
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define HIWORD(l)
Definition: typedefs.h:247
#define OUT
Definition: typedefs.h:40
#define AddItem
Definition: userenv.h:209
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY Policy
Definition: wdfinterrupt.h:653
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:1966
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define BST_UNCHECKED
Definition: winuser.h:199
#define WM_COMMAND
Definition: winuser.h:1740
#define CB_ERR
Definition: winuser.h:2435
#define CB_SETCURSEL
Definition: winuser.h:1961
#define CB_RESETCONTENT
Definition: winuser.h:1959
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define CBN_SELCHANGE
Definition: winuser.h:1979
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define CB_GETITEMDATA
Definition: winuser.h:1950
#define SendMessage
Definition: winuser.h:5843
#define MB_OK
Definition: winuser.h:790
HWND WINAPI GetParent(_In_ HWND)
#define LoadString
Definition: winuser.h:5819
#define MessageBox
Definition: winuser.h:5822
#define WM_USER
Definition: winuser.h:1895
#define BN_CLICKED
Definition: winuser.h:1925
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
#define CB_INSERTSTRING
Definition: winuser.h:1957
#define CB_GETCURSEL
Definition: winuser.h:1943
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define BST_CHECKED
Definition: winuser.h:197
char TCHAR
Definition: xmlstorage.h:189