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

Go to the source code of this file.

Classes

struct  POWER_METER_INFO
 

Typedefs

typedef struct POWER_METER_INFOPPOWER_METER_INFO
 

Functions

static VOID PowerMeterInfo_UpdateGlobalStats (_In_ PPOWER_METER_INFO ppmi)
 
static BOOL PowerMeterInfo_UpdateBatteryStats (_In_ PPOWER_METER_INFO ppmi, _In_ UINT BatteryId)
 
static VOID PowerMeterDetail_UpdateStats (HWND hwndDlg)
 
static VOID PowerMeterDetail_InitDialog (HWND hwndDlg)
 
static VOID CenterWindow (_In_ HWND hWnd)
 
INT_PTR CALLBACK PowerMeterDetailDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static DWORD WINAPI PowerMeterDetailDlgThread (PVOID pParam)
 
static HICON GetBattIcon (_In_ HINSTANCE hInst, _In_ PPOWER_METER_INFO ppmi)
 
static VOID PowerMeter_InitDialog (HWND hwndDlg)
 
INT_PTR CALLBACK PowerMeterDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 

Variables

static UINT SelectedBattery = 0
 ID of battery currently shown in the details dialog.
 
static HWND hwndDlgDetail = NULL
 Single modeless battery details dialog.
 

Typedef Documentation

◆ PPOWER_METER_INFO

Function Documentation

◆ CenterWindow()

static VOID CenterWindow ( _In_ HWND  hWnd)
static

Definition at line 266 of file powermeter.c.

267{
269 RECT rcParent, rcWindow;
270 SIZE size;
271 POINT pos;
273 HMONITOR hMonitor;
274
276 if (hWndParent == NULL)
278
279 GetWindowRect(hWndParent, &rcParent);
280 GetWindowRect(hWnd, &rcWindow);
281 size.cx = rcWindow.right - rcWindow.left;
282 size.cy = rcWindow.bottom - rcWindow.top;
283
284 mi.cbSize = sizeof(mi);
285 // hMonitor = MonitorFromRect(rcParent, MONITOR_DEFAULTTONEAREST);
286 hMonitor = MonitorFromWindow(hWndParent, MONITOR_DEFAULTTONEAREST);
287 GetMonitorInfoW(hMonitor, &mi);
288
289 /* Center the window with respect to its parent. Formula:
290 * with: pL = parent.left, pR = parent.right, w = window width,
291 * X = pL + (pR - pL - w) / 2; and similar for Y, top, bottom, height. */
292 pos.x = (rcParent.right + rcParent.left - size.cx) / 2;
293 pos.y = (rcParent.bottom + rcParent.top - size.cy) / 2;
294
295 /* Clip it to the monitor work area, so that top-left stays visible */
296 pos.x = max(mi.rcWork.left, min(pos.x, mi.rcWork.right - size.cx));
297 pos.y = max(mi.rcWork.top, min(pos.y, mi.rcWork.bottom - size.cy));
298
300}
HWND hWnd
Definition: settings.c:17
#define NULL
Definition: types.h:112
GLsizeiptr size
Definition: glext.h:5919
static MONITORINFO mi
Definition: win.c:7338
#define min(a, b)
Definition: monoChain.cc:55
HMONITOR WINAPI MonitorFromWindow(HWND, DWORD)
DWORD cbSize
Definition: winuser.h:3886
Definition: windef.h:99
LONG right
Definition: windef.h:102
LONG bottom
Definition: windef.h:103
LONG top
Definition: windef.h:101
LONG left
Definition: windef.h:100
#define max(a, b)
Definition: svc.c:63
#define SWP_NOACTIVATE
Definition: winuser.h:1253
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOSIZE
Definition: winuser.h:1256
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:628
#define HWND_TOP
Definition: winuser.h:1218
HWND WINAPI GetParent(_In_ HWND)
BOOL WINAPI GetMonitorInfoW(_In_ HMONITOR, _Inout_ LPMONITORINFO)
#define SWP_NOZORDER
Definition: winuser.h:1258

Referenced by PowerMeterDetailDlgProc().

◆ GetBattIcon()

static HICON GetBattIcon ( _In_ HINSTANCE  hInst,
_In_ PPOWER_METER_INFO  ppmi 
)
static

Definition at line 362 of file powermeter.c.

365{
366 UINT uIDIcon = IDI_BAT_UNKNOWN;
367
368 // gGPP.user.DischargePolicy[DISCHARGE_POLICY_CRITICAL].BatteryLevel
369 if (ppmi->Critical || (0 <= ppmi->BatteryLifePercent && ppmi->BatteryLifePercent < 5)) // FIXME: Find which percentage is critical?
370 uIDIcon = (ppmi->Charging ? IDI_BAT_CHARGE_CRIT : IDI_BAT_DISCHRG_CRIT);
371 else if (5 <= ppmi->BatteryLifePercent && ppmi->BatteryLifePercent < 33)
372 uIDIcon = (ppmi->Charging ? IDI_BAT_CHARGE_LOW : IDI_BAT_DISCHRG_LOW);
373 else if (33 <= ppmi->BatteryLifePercent && ppmi->BatteryLifePercent < 66)
374 uIDIcon = (ppmi->Charging ? IDI_BAT_CHARGE_HALF : IDI_BAT_DISCHRG_HALF);
375 else if (66 <= ppmi->BatteryLifePercent && ppmi->BatteryLifePercent < 100)
376 uIDIcon = (ppmi->Charging ? IDI_BAT_CHARGE_HIGH : IDI_BAT_DISCHRG_HIGH);
377 else if (ppmi->BatteryLifePercent >= 100)
378 uIDIcon = (ppmi->Charging ? IDI_BAT_CHARGE_FULL : IDI_BAT_DISCHRG_FULL);
379
380 return LoadIconW(hApplet, MAKEINTRESOURCEW(uIDIcon));
381}
HINSTANCE hApplet
Definition: access.c:17
#define IDI_BAT_DISCHRG_LOW
Definition: resource.h:36
#define IDI_BAT_CHARGE_FULL
Definition: resource.h:33
#define IDI_BAT_DISCHRG_HALF
Definition: resource.h:37
#define IDI_BAT_CHARGE_HIGH
Definition: resource.h:32
#define IDI_BAT_CHARGE_LOW
Definition: resource.h:30
#define IDI_BAT_UNKNOWN
Definition: resource.h:41
#define IDI_BAT_CHARGE_HALF
Definition: resource.h:31
#define IDI_BAT_DISCHRG_HIGH
Definition: resource.h:38
#define IDI_BAT_DISCHRG_CRIT
Definition: resource.h:35
#define IDI_BAT_DISCHRG_FULL
Definition: resource.h:39
#define IDI_BAT_CHARGE_CRIT
Definition: resource.h:29
unsigned int UINT
Definition: ndis.h:50
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2427

Referenced by PowerMeter_InitDialog().

◆ PowerMeter_InitDialog()

static VOID PowerMeter_InitDialog ( HWND  hwndDlg)
static

Definition at line 385 of file powermeter.c.

386{
388 HICON hIcon;
389 UINT BatteryId;
390 WCHAR szPercent[5];
391 WCHAR Buffer[200];
392
395
397 if (pmi.ACOnline)
398 {
401
404 }
405 else
406 {
407 hIcon = GetBattIcon(hApplet, &pmi);
409 // DeleteObject(hIcon);
410
413 }
416
417 /* Check whether to show only the composite battery gauge, or the individual battery details */
419 {
420 /* Hide the individual battery controls */
421 for (BatteryId = 0; BatteryId < 8; ++BatteryId)
422 {
423 ShowWindow(GetDlgItem(hwndDlg, IDC_BATTERY0 + BatteryId), SW_HIDE);
424 ShowWindow(GetDlgItem(hwndDlg, IDI_BATTERYDETAIL0 + BatteryId), SW_HIDE);
425 ShowWindow(GetDlgItem(hwndDlg, IDC_BATTERYPERCENT0 + BatteryId), SW_HIDE);
426 ShowWindow(GetDlgItem(hwndDlg, IDC_BATTERYCHARGING0 + BatteryId), SW_HIDE);
427 }
429
430 /* Show the composite battery gauge and set it up (0 to 100%) */
434 return;
435 }
436
437 /* Hide the composite battery gauge */
439
440 /* Show or hide the individual battery controls */
442 for (BatteryId = 0; BatteryId < 8; ++BatteryId)
443 {
444 if (!PowerMeterInfo_UpdateBatteryStats(&pmi, BatteryId))
445 break;
446
447 ShowWindow(GetDlgItem(hwndDlg, IDC_BATTERY0 + BatteryId), SW_SHOW);
448 ShowWindow(GetDlgItem(hwndDlg, IDI_BATTERYDETAIL0 + BatteryId), SW_SHOW);
449 ShowWindow(GetDlgItem(hwndDlg, IDC_BATTERYPERCENT0 + BatteryId), SW_SHOW);
450 ShowWindow(GetDlgItem(hwndDlg, IDC_BATTERYCHARGING0 + BatteryId), SW_SHOW);
451
452 hIcon = GetBattIcon(hApplet, &pmi);
454 // DeleteObject(hIcon);
455
456 if (pmi.Charging)
457 {
459 SetDlgItemTextW(hwndDlg, IDC_BATTERYCHARGING0 + BatteryId, Buffer);
460 }
461 else
462 {
464 SetDlgItemTextW(hwndDlg, IDC_BATTERYCHARGING0 + BatteryId, Buffer);
465 }
467 SetDlgItemTextW(hwndDlg, IDC_BATTERYPERCENT0 + BatteryId, Buffer);
468 }
469 for (; BatteryId < 8; ++BatteryId)
470 {
471 ShowWindow(GetDlgItem(hwndDlg, IDC_BATTERY0 + BatteryId), SW_HIDE);
472 ShowWindow(GetDlgItem(hwndDlg, IDI_BATTERYDETAIL0 + BatteryId), SW_HIDE);
473 ShowWindow(GetDlgItem(hwndDlg, IDC_BATTERYPERCENT0 + BatteryId), SW_HIDE);
474 ShowWindow(GetDlgItem(hwndDlg, IDC_BATTERYCHARGING0 + BatteryId), SW_HIDE);
475 }
476}
Definition: bufpool.h:45
#define IDC_BATTPROGRESS
Definition: resource.h:168
#define IDC_BATTERYCHARGING0
Definition: resource.h:196
#define IDS_PERCENT
Definition: resource.h:47
#define IDS_OFFLINE
Definition: resource.h:91
#define IDC_BATTERYPERCENT0
Definition: resource.h:188
#define IDI_AC
Definition: resource.h:23
#define IDS_ONLINE
Definition: resource.h:93
#define IDC_IPOWERSOURCE
Definition: resource.h:165
#define IDC_SHOWDETAILS
Definition: resource.h:164
#define IDC_POWERSTATUS
Definition: resource.h:167
#define IDS_CHARGING
Definition: resource.h:92
#define IDI_BATTERYDETAIL0
Definition: resource.h:180
#define IDC_CLICKBATTINFO
Definition: resource.h:169
#define IDC_BATTERY0
Definition: resource.h:172
#define IDC_POWERSOURCE
Definition: resource.h:166
#define IDS_DISCHARGING
Definition: resource.h:100
static const WCHAR szPercent[]
Definition: varformat.c:393
UINT_PTR WPARAM
Definition: minwindef.h:174
static HICON
Definition: imagelist.c:80
HICON hIcon
Definition: msconfig.c:44
#define UNICODE_NULL
static VOID PowerMeterInfo_UpdateGlobalStats(_In_ PPOWER_METER_INFO ppmi)
Definition: powermeter.c:30
static BOOL PowerMeterInfo_UpdateBatteryStats(_In_ PPOWER_METER_INFO ppmi, _In_ UINT BatteryId)
Definition: powermeter.c:49
static HICON GetBattIcon(_In_ HINSTANCE hInst, _In_ PPOWER_METER_INFO ppmi)
Definition: powermeter.c:362
#define PBM_SETPOS
Definition: commctrl.h:2189
#define PBM_SETRANGE
Definition: commctrl.h:2188
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
BYTE BatteryLifePercent
Definition: powermeter.c:24
#define SW_HIDE
Definition: winuser.h:779
#define MAKELPARAM(l, h)
Definition: winuser.h:4110
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define STM_SETICON
Definition: winuser.h:2128
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define LoadString
Definition: winuser.h:5930
#define SW_SHOW
Definition: winuser.h:786
#define BST_CHECKED
Definition: winuser.h:197
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by PowerMeterDlgProc().

◆ PowerMeterDetail_InitDialog()

static VOID PowerMeterDetail_InitDialog ( HWND  hwndDlg)
static

Definition at line 252 of file powermeter.c.

253{
254 WCHAR FormatBuffer[200];
255 WCHAR Buffer[200];
256
257 if (LoadString(hApplet, IDS_DETAILEDBATTERY, FormatBuffer, _countof(FormatBuffer)))
258 {
260 SetWindowTextW(hwndDlg, Buffer);
261 }
263}
#define IDS_DETAILEDBATTERY
Definition: resource.h:94
static VOID PowerMeterDetail_UpdateStats(HWND hwndDlg)
Definition: powermeter.c:202
static UINT SelectedBattery
ID of battery currently shown in the details dialog.
Definition: powermeter.c:12
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)

Referenced by PowerMeterDetailDlgProc().

◆ PowerMeterDetail_UpdateStats()

static VOID PowerMeterDetail_UpdateStats ( HWND  hwndDlg)
static

Definition at line 202 of file powermeter.c.

203{
205 WCHAR Status[200];
206 WCHAR Buffer[200];
207
209
210 SetDlgItemTextW(hwndDlg, IDC_BATTERYNAME, pmi.Name);
213
214 Status[0] = UNICODE_NULL;
215 if (pmi.ACOnline)
216 {
218 {
220 }
221 }
222 if (pmi.Charging)
223 {
225 {
226 if (Status[0] != UNICODE_NULL)
227 {
228 wcscat(Status, L", ");
229 }
231 }
232 }
233 else
234 {
236 {
237 if (Status[0] != UNICODE_NULL)
238 {
239 wcscat(Status, L", ");
240 }
242 }
243 }
244 // TODO BATTERY_CRITICAL
246
248}
wcscat
wcscpy
#define IDC_BATTERYMANUFACTURER
Definition: resource.h:99
#define IDC_BATTERYPOWERSTATE
Definition: resource.h:98
#define IDC_BATTERYNAME
Definition: resource.h:95
#define IDC_BATTERYCHEMISTRY
Definition: resource.h:97
#define IDC_BATTERYUNIQUEID
Definition: resource.h:96
#define L(x)
Definition: resources.c:13
Status
Definition: gdiplustypes.h:25
WCHAR UniqueID[200]
Definition: powermeter.c:18
WCHAR Manufacturer[200]
Definition: powermeter.c:19
WCHAR Name[200]
Definition: powermeter.c:17
BOOL WINAPI SetDlgItemTextA(_In_ HWND, _In_ int, _In_ LPCSTR)

Referenced by PowerMeterDetail_InitDialog().

◆ PowerMeterDetailDlgProc()

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

Definition at line 304 of file powermeter.c.

305{
306 switch (uMsg)
307 {
308 case WM_INITDIALOG:
309 {
311 CenterWindow(hwndDlg);
312 hwndDlgDetail = hwndDlg;
313 return TRUE;
314 }
315
316 case WM_ACTIVATE:
317 {
318 /* Refresh the dialog on activation */
319 if (LOWORD(wParam) != WA_INACTIVE)
321 break;
322 }
323
324 case WM_COMMAND:
325 switch (LOWORD(wParam))
326 {
327 case IDC_REFRESH:
329 break;
330
331 case IDOK:
332 case IDCANCEL:
334 // DestroyWindow(hwndDlgDetail);
335 EndDialog(hwndDlg, 0);
336 return TRUE;
337
338 default:
339 break;
340 }
341 }
342 return FALSE;
343}
WPARAM wParam
Definition: combotst.c:138
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IDC_REFRESH
Definition: resource.h:170
#define LOWORD(l)
Definition: pedump.c:82
static VOID CenterWindow(_In_ HWND hWnd)
Definition: powermeter.c:266
static VOID PowerMeterDetail_InitDialog(HWND hwndDlg)
Definition: powermeter.c:252
static HWND hwndDlgDetail
Single modeless battery details dialog.
Definition: powermeter.c:13
#define IDCANCEL
Definition: winuser.h:842
#define WM_COMMAND
Definition: winuser.h:1768
#define WA_INACTIVE
Definition: winuser.h:2664
#define WM_INITDIALOG
Definition: winuser.h:1767
#define IDOK
Definition: winuser.h:841
#define WM_ACTIVATE
Definition: winuser.h:1640
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)

Referenced by PowerMeterDetailDlgThread().

◆ PowerMeterDetailDlgThread()

static DWORD WINAPI PowerMeterDetailDlgThread ( PVOID  pParam)
static

Definition at line 346 of file powermeter.c.

347{
348 // HWND hwndDlg = (HWND)pParam;
349
350 /* Use DialogBoxW() instead of CreateDialogW(), so that we can directly
351 * use the default dialog message loop implementation furnished for modal
352 * dialog boxes, instead of doing it ourselves for a modeless dialog.
353 * But, set the parent to NULL so that we behave "like" a modeless dialog. */
354 // hwndDlgDetail =
356 return 0;
357}
#define IDD_POWERMETERDETAILS
Definition: resource.h:60
INT_PTR CALLBACK PowerMeterDetailDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: powermeter.c:304
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4501

Referenced by PowerMeterDlgProc().

◆ PowerMeterDlgProc()

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

Definition at line 481 of file powermeter.c.

482{
483 switch (uMsg)
484 {
485 case WM_INITDIALOG:
486 PowerMeter_InitDialog(hwndDlg);
487 return TRUE;
488
489 case WM_COMMAND:
491 {
492 PowerMeter_InitDialog(hwndDlg);
493 break;
494 }
496 {
499 {
502 (PVOID)hwndDlg,
503 0, NULL);
504 if (Thread)
506 }
507 else
508 {
509 /* Activate the existing window */
512 }
513 }
514 break;
515 }
516 return FALSE;
517}
#define IDI_BATTERYDETAIL7
Definition: resource.h:187
#define CloseHandle
Definition: compat.h:739
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
static DWORD WINAPI PowerMeterDetailDlgThread(PVOID pParam)
Definition: powermeter.c:346
static VOID PowerMeter_InitDialog(HWND hwndDlg)
Definition: powermeter.c:385
VOID WINAPI SwitchToThisWindow(HWND hwnd, BOOL fAltTab)
Definition: window.c:82
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define SW_SHOWNA
Definition: winuser.h:789

Referenced by Applet().

◆ PowerMeterInfo_UpdateBatteryStats()

static BOOL PowerMeterInfo_UpdateBatteryStats ( _In_ PPOWER_METER_INFO  ppmi,
_In_ UINT  BatteryId 
)
static

Definition at line 49 of file powermeter.c.

52{
53 HDEVINFO hDevInfo;
57 HANDLE hDevice;
58 DWORD dwWait;
59 DWORD dwReceived;
61 BATTERY_INFORMATION bi = {0};
62 BATTERY_WAIT_STATUS bws = {0};
64
65 ZeroMemory(ppmi, sizeof(*ppmi));
66
67 hDevInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_BATTERY, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
68 if (hDevInfo == INVALID_HANDLE_VALUE)
69 {
70 DPRINT1("SetupDiGetClassDevsW failed with %x\n", GetLastError());
71 return FALSE;
72 }
73
74 InfoData.cbSize = sizeof(InfoData);
75 if (!SetupDiEnumDeviceInterfaces(hDevInfo, 0, &GUID_DEVCLASS_BATTERY, BatteryId, &InfoData))
76 {
77 DPRINT("SetupDiEnumDeviceInterfaces failed with %x\n", GetLastError());
79 return FALSE;
80 }
81
82 dwSize = 0;
83 InterfaceData = NULL;
84 if (!SetupDiGetInterfaceDeviceDetailW(hDevInfo, &InfoData, InterfaceData, dwSize, &dwSize, NULL))
85 {
87 {
88 DPRINT1("SetupDiGetInterfaceDeviceDetailW failed with %x\n", GetLastError());
90 return FALSE;
91 }
92 }
94 if (!InterfaceData)
95 {
96 DPRINT1("HeapAlloc failed with %x\n", GetLastError());
98 return FALSE;
99 }
100 InterfaceData->cbSize = sizeof(*InterfaceData);
101 if (!SetupDiGetInterfaceDeviceDetailW(hDevInfo, &InfoData, InterfaceData, dwSize, &dwSize, NULL))
102 {
103 DPRINT1("SetupDiGetInterfaceDeviceDetailW failed with %x\n", GetLastError());
104 HeapFree(GetProcessHeap(), 0, InterfaceData);
106 return FALSE;
107 }
108
109 DPRINT("Opening battery %S\n", InterfaceData->DevicePath);
110 hDevice = CreateFileW(
113 if (hDevice == INVALID_HANDLE_VALUE)
114 {
115 DPRINT1("CreateFileW failed with %x\n", GetLastError());
116 HeapFree(GetProcessHeap(), 0, InterfaceData);
118 return FALSE;
119 }
120
121 dwWait = 0;
123 &dwWait, sizeof(dwWait), &bqi.BatteryTag, sizeof(bqi.BatteryTag),
124 &dwReceived, NULL))
125 {
128 &bqi, sizeof(bqi), ppmi->Name, sizeof(ppmi->Name),
129 &dwReceived, NULL))
130 {
131 ppmi->Name[dwReceived / sizeof(WCHAR)] = UNICODE_NULL;
132 }
133 else
134 {
135 ppmi->Name[0] = UNICODE_NULL;
136 }
137
140 &bqi, sizeof(bqi), ppmi->UniqueID, sizeof(ppmi->UniqueID),
141 &dwReceived, NULL))
142 {
143 ppmi->UniqueID[dwReceived / sizeof(WCHAR)] = UNICODE_NULL;
144 }
145 else
146 {
147 ppmi->UniqueID[0] = UNICODE_NULL;
148 }
149
152 &bqi, sizeof(bqi), &bi, sizeof(bi),
153 &dwReceived, NULL))
154 {
155 RtlCopyMemory(ppmi->Chem, bi.Chemistry, sizeof(bi.Chemistry));
156 ppmi->Chem[4] = ANSI_NULL;
157 }
158 else
159 {
160 ppmi->Chem[0] = ANSI_NULL;
161 }
162
163 bws.BatteryTag = bqi.BatteryTag;
165 &bws, sizeof(bws), &bs, sizeof(bs),
166 &dwReceived, NULL))
167 {
168 ppmi->ACOnline = !!(bs.PowerState & BATTERY_POWER_ON_LINE);
169 ppmi->Charging = (bs.PowerState & BATTERY_CHARGING) && !(bs.PowerState & BATTERY_DISCHARGING);
170 ppmi->Critical = !!(bs.PowerState & BATTERY_CRITICAL);
171 ppmi->BatteryLifePercent = 100 * bs.Capacity / bi.FullChargedCapacity;
172 ppmi->BatteryLifeTime = BATTERY_LIFE_UNKNOWN;
173 }
174
177 &bqi, sizeof(bqi), &ppmi->BatteryLifeTime, sizeof(ppmi->BatteryLifeTime),
178 &dwReceived, NULL))
179 {
180 ppmi->BatteryLifeTime = BATTERY_LIFE_UNKNOWN; // == BATTERY_UNKNOWN_TIME;
181 }
182
185 &bqi, sizeof(bqi), ppmi->Manufacturer, sizeof(ppmi->Manufacturer),
186 &dwReceived, NULL))
187 {
188 ppmi->Manufacturer[dwReceived / sizeof(WCHAR)] = UNICODE_NULL;
189 }
190 else
191 {
192 ppmi->Manufacturer[0] = UNICODE_NULL;
193 }
194 }
195 HeapFree(GetProcessHeap(), 0, InterfaceData);
197 return TRUE;
198}
#define DPRINT1
Definition: precomp.h:8
#define IOCTL_BATTERY_QUERY_TAG
Definition: batclass.h:84
#define BATTERY_CRITICAL
Definition: batclass.h:76
#define BATTERY_POWER_ON_LINE
Definition: batclass.h:73
#define BATTERY_DISCHARGING
Definition: batclass.h:74
@ BatteryInformation
Definition: batclass.h:97
@ BatteryManufactureName
Definition: batclass.h:103
@ BatteryUniqueID
Definition: batclass.h:104
@ BatteryEstimatedTime
Definition: batclass.h:100
@ BatteryDeviceName
Definition: batclass.h:101
#define IOCTL_BATTERY_QUERY_INFORMATION
Definition: batclass.h:86
#define BATTERY_CHARGING
Definition: batclass.h:75
#define IOCTL_BATTERY_QUERY_STATUS
Definition: batclass.h:90
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define GetProcessHeap()
Definition: compat.h:736
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define GENERIC_READ
Definition: compat.h:135
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2780
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2292
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2893
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ZeroMemory
Definition: minwinbase.h:31
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ANSI_NULL
#define SetupDiGetInterfaceDeviceDetailW
Definition: setupapi.h:2430
#define DIGCF_PRESENT
Definition: setupapi.h:172
#define DIGCF_INTERFACEDEVICE
Definition: setupapi.h:176
#define DPRINT
Definition: sndvol32.h:73
UCHAR Chemistry[4]
Definition: batclass.h:118
ULONG FullChargedCapacity
Definition: batclass.h:120
BATTERY_QUERY_INFORMATION_LEVEL InformationLevel
Definition: batclass.h:110
WCHAR DevicePath[ANYSIZE_ARRAY]
Definition: setupapi.h:856
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define BATTERY_LIFE_UNKNOWN
Definition: winbase.h:502
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by PowerMeter_InitDialog(), and PowerMeterDetail_UpdateStats().

◆ PowerMeterInfo_UpdateGlobalStats()

static VOID PowerMeterInfo_UpdateGlobalStats ( _In_ PPOWER_METER_INFO  ppmi)
static

Definition at line 30 of file powermeter.c.

32{
34
35 ZeroMemory(ppmi, sizeof(*ppmi));
36
37 if (GetSystemPowerStatus(&sps))
38 {
39 ppmi->ACOnline = (sps.ACLineStatus != 0);
40 ppmi->Charging = !!(sps.BatteryFlag & BATTERY_FLAG_CHARGING);
41 ppmi->Critical = !!(sps.BatteryFlag & BATTERY_FLAG_CRITICAL);
42 ppmi->BatteryLifePercent = sps.BatteryLifePercent;
43 ppmi->BatteryLifeTime = sps.BatteryLifeTime;
44 }
45}
BOOL WINAPI GetSystemPowerStatus(IN LPSYSTEM_POWER_STATUS PowerStatus)
Definition: power.c:27
#define BATTERY_FLAG_CHARGING
Definition: winbase.h:498
#define BATTERY_FLAG_CRITICAL
Definition: winbase.h:497

Referenced by PowerMeter_InitDialog().

Variable Documentation

◆ hwndDlgDetail

HWND hwndDlgDetail = NULL
static

Single modeless battery details dialog.

Definition at line 13 of file powermeter.c.

Referenced by PowerMeterDetailDlgProc(), and PowerMeterDlgProc().

◆ SelectedBattery

UINT SelectedBattery = 0
static

ID of battery currently shown in the details dialog.

Definition at line 12 of file powermeter.c.

Referenced by PowerMeterDetail_InitDialog(), PowerMeterDetail_UpdateStats(), and PowerMeterDlgProc().