ReactOS 0.4.16-dev-1408-gbc64f3a
powermeter.c File Reference
#include "powercfg.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 (PPOWER_METER_INFO ppmi)
 
static BOOL PowerMeterInfo_UpdateBatteryStats (PPOWER_METER_INFO ppmi)
 
static VOID PowerMeterDetail_UpdateStats (HWND hwndDlg)
 
static VOID PowerMeterDetail_InitDialog (HWND hwndDlg)
 
INT_PTR CALLBACK PowerMeterDetailDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static VOID PowerMeter_InitDialog (HWND hwndDlg)
 
INT_PTR CALLBACK PowerMeterDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 

Variables

static int SelectedBattery = 0
 
static HWND hwndDlgDetail = 0
 

Typedef Documentation

◆ PPOWER_METER_INFO

Function Documentation

◆ PowerMeter_InitDialog()

static VOID PowerMeter_InitDialog ( HWND  hwndDlg)
static

Definition at line 283 of file powermeter.c.

284{
286 WCHAR Buffer[200];
287
289 if (pmi.ACOnline)
290 {
291 if (LoadString(hApplet, IDS_ONLINE, Buffer, sizeof(Buffer) / sizeof(WCHAR)))
292 {
294 }
295 }
296 else
297 {
298 if (LoadString(hApplet, IDS_OFFLINE, Buffer, sizeof(Buffer) / sizeof(WCHAR)))
299 {
301 }
302 }
303 if (pmi.Charging)
304 {
305 if (LoadString(hApplet, IDS_CHARGING, Buffer, sizeof(Buffer) / sizeof(WCHAR)))
306 {
308 }
309 }
310 else
311 {
312 if (LoadString(hApplet, IDS_DISCHARGING, Buffer, sizeof(Buffer) / sizeof(WCHAR)))
313 {
315 }
316 }
317 wsprintf(Buffer, L"%d %%", pmi.BatteryLifePercent);
319
321 {
323 break;
324
329 if (pmi.Charging)
330 {
331 if (LoadString(hApplet, IDS_CHARGING, Buffer, sizeof(Buffer) / sizeof(WCHAR)))
332 {
334 }
335 }
336 else
337 {
338 if (LoadString(hApplet, IDS_DISCHARGING, Buffer, sizeof(Buffer) / sizeof(WCHAR)))
339 {
341 }
342 }
343 wsprintf(Buffer, L"%d %%", pmi.BatteryLifePercent);
345 }
346 for (; SelectedBattery < 8; SelectedBattery++)
347 {
352 }
353}
Definition: bufpool.h:45
HINSTANCE hApplet
Definition: access.c:17
#define IDC_BATTERYCHARGING0
Definition: resource.h:161
#define IDS_OFFLINE
Definition: resource.h:52
#define IDC_BATTERYPERCENT0
Definition: resource.h:153
#define IDS_ONLINE
Definition: resource.h:54
#define IDC_POWERSTATUS
Definition: resource.h:134
#define IDS_CHARGING
Definition: resource.h:53
#define IDI_BATTERYDETAIL0
Definition: resource.h:145
#define IDC_BATTERY0
Definition: resource.h:137
#define IDC_POWERSOURCE
Definition: resource.h:133
#define IDS_DISCHARGING
Definition: resource.h:61
#define L(x)
Definition: resources.c:13
static VOID PowerMeterInfo_UpdateGlobalStats(PPOWER_METER_INFO ppmi)
Definition: powermeter.c:32
static BOOL PowerMeterInfo_UpdateBatteryStats(PPOWER_METER_INFO ppmi)
Definition: powermeter.c:48
static int SelectedBattery
Definition: powermeter.c:14
BYTE BatteryLifePercent
Definition: powermeter.c:26
#define SW_HIDE
Definition: winuser.h:779
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define wsprintf
Definition: winuser.h:5950
#define LoadString
Definition: winuser.h:5904
#define SW_SHOW
Definition: winuser.h:786
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by PowerMeterDlgProc().

◆ PowerMeterDetail_InitDialog()

static VOID PowerMeterDetail_InitDialog ( HWND  hwndDlg)
static

Definition at line 241 of file powermeter.c.

242{
243 WCHAR FormatBuffer[200];
244 WCHAR Buffer[200];
245
246 if (LoadString(hApplet, IDS_DETAILEDBATTERY, FormatBuffer, sizeof(Buffer) / sizeof(WCHAR)))
247 {
248 wsprintf(Buffer, FormatBuffer, SelectedBattery + 1);
249 SetWindowTextW(hwndDlg, Buffer);
250 }
252}
#define IDS_DETAILEDBATTERY
Definition: resource.h:55
static VOID PowerMeterDetail_UpdateStats(HWND hwndDlg)
Definition: powermeter.c:190
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)

Referenced by PowerMeterDetailDlgProc().

◆ PowerMeterDetail_UpdateStats()

static VOID PowerMeterDetail_UpdateStats ( HWND  hwndDlg)
static

Definition at line 190 of file powermeter.c.

191{
193 WCHAR Status[200];
194 WCHAR Buffer[200];
195
197
198 SetDlgItemTextW(hwndDlg, IDC_BATTERYNAME, pmi.Name);
201
202 Status[0] = UNICODE_NULL;
203 if (pmi.ACOnline)
204 {
205 if (LoadString(hApplet, IDS_ONLINE, Buffer, sizeof(Buffer) / sizeof(WCHAR)))
206 {
208 }
209 }
210 if (pmi.Charging)
211 {
212 if (LoadString(hApplet, IDS_CHARGING, Buffer, sizeof(Buffer) / sizeof(WCHAR)))
213 {
214 if (Status[0] != UNICODE_NULL)
215 {
216 wcscat(Status, L", ");
217 }
219 }
220 }
221 else
222 {
223 if (LoadString(hApplet, IDS_DISCHARGING, Buffer, sizeof(Buffer) / sizeof(WCHAR)))
224 {
225 if (Status[0] != UNICODE_NULL)
226 {
227 wcscat(Status, L", ");
228 }
230 }
231 }
232 // TODO BATTERY_CRITICAL
234
236}
wcscat
wcscpy
#define IDC_BATTERYMANUFACTURER
Definition: resource.h:60
#define IDC_BATTERYPOWERSTATE
Definition: resource.h:59
#define IDC_BATTERYNAME
Definition: resource.h:56
#define IDC_BATTERYCHEMISTRY
Definition: resource.h:58
#define IDC_BATTERYUNIQUEID
Definition: resource.h:57
Status
Definition: gdiplustypes.h:25
#define UNICODE_NULL
WCHAR UniqueID[200]
Definition: powermeter.c:20
WCHAR Manufacturer[200]
Definition: powermeter.c:21
WCHAR Name[200]
Definition: powermeter.c:19
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 256 of file powermeter.c.

257{
258 switch (uMsg)
259 {
260 case WM_INITDIALOG:
262 return TRUE;
263 case WM_COMMAND:
264 if (LOWORD(wParam) == IDC_REFRESH)
265 {
267 break;
268 }
269 else if (LOWORD(wParam) == IDOK)
270 {
272 hwndDlgDetail = 0;
273 return TRUE;
274 }
275
276 }
277 return FALSE;
278}
WPARAM wParam
Definition: combotst.c:138
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IDC_REFRESH
Definition: resource.h:135
#define LOWORD(l)
Definition: pedump.c:82
static VOID PowerMeterDetail_InitDialog(HWND hwndDlg)
Definition: powermeter.c:241
static HWND hwndDlgDetail
Definition: powermeter.c:15
#define WM_COMMAND
Definition: winuser.h:1759
#define WM_INITDIALOG
Definition: winuser.h:1758
#define IDOK
Definition: winuser.h:841
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by PowerMeterDlgProc().

◆ PowerMeterDlgProc()

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

Definition at line 358 of file powermeter.c.

359{
360 switch (uMsg)
361 {
362 case WM_INITDIALOG:
363 PowerMeter_InitDialog(hwndDlg);
364 return TRUE;
365 case WM_COMMAND:
367 {
369 {
374 }
375
376 }
377 break;
378 }
379 return FALSE;
380}
#define IDD_POWERMETERDETAILS
Definition: resource.h:21
#define IDI_BATTERYDETAIL7
Definition: resource.h:152
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
static VOID PowerMeter_InitDialog(HWND hwndDlg)
Definition: powermeter.c:283
INT_PTR CALLBACK PowerMeterDetailDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: powermeter.c:256
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define CreateDialog
Definition: winuser.h:5834

Referenced by Applet1().

◆ PowerMeterInfo_UpdateBatteryStats()

static BOOL PowerMeterInfo_UpdateBatteryStats ( PPOWER_METER_INFO  ppmi)
static

Definition at line 48 of file powermeter.c.

49{
50 HDEVINFO hDevInfo;
52 DWORD dwIndex;
55 HANDLE hDevice;
56 DWORD dwWait;
57 DWORD dwReceived;
59 BATTERY_INFORMATION bi = {0};
60 BATTERY_WAIT_STATUS bws = {0};
62
63 hDevInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_BATTERY, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
64 if (hDevInfo == INVALID_HANDLE_VALUE)
65 {
66 DPRINT1("SetupDiGetClassDevsW failed with %x\n", GetLastError());
67 return FALSE;
68 }
69
70 InfoData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
71 dwIndex = SelectedBattery;
72 if (!SetupDiEnumDeviceInterfaces(hDevInfo, 0, &GUID_DEVCLASS_BATTERY, dwIndex, &InfoData))
73 {
74 DPRINT("SetupDiEnumDeviceInterfaces failed with %x\n", GetLastError());
76 return FALSE;
77 }
78
79 dwSize = 0;
80 InterfaceData = NULL;
81 if (!SetupDiGetInterfaceDeviceDetailW(hDevInfo, &InfoData, InterfaceData, dwSize, &dwSize, NULL))
82 {
84 {
85 DPRINT1("SetupDiGetInterfaceDeviceDetailW failed with %x\n", GetLastError());
87 return FALSE;
88 }
89 }
91 if (!InterfaceData)
92 {
93 DPRINT1("HeapAlloc failed with %x\n", GetLastError());
95 return FALSE;
96 }
97 InterfaceData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W);
98 if (!SetupDiGetInterfaceDeviceDetailW(hDevInfo, &InfoData, InterfaceData, dwSize, &dwSize, NULL))
99 {
100 DPRINT1("SetupDiGetInterfaceDeviceDetailW failed with %x\n", GetLastError());
101 HeapFree(GetProcessHeap(), 0, InterfaceData);
103 return FALSE;
104 }
105
106 DPRINT("Opening battery %S\n", InterfaceData->DevicePath);
107 hDevice = CreateFileW(
110 if (hDevice == INVALID_HANDLE_VALUE)
111 {
112 DPRINT1("CreateFileW failed with %x\n", GetLastError());
113 HeapFree(GetProcessHeap(), 0, InterfaceData);
115 return FALSE;
116 }
117
118 dwWait = 0;
120 &dwWait, sizeof(DWORD), &bqi.BatteryTag, sizeof(bqi.BatteryTag),
121 &dwReceived,
122 NULL))
123 {
124
127 &bqi, sizeof(bqi), ppmi->Name, sizeof(ppmi->Name),
128 &dwReceived,
129 NULL))
130 {
131 ppmi->Name[dwReceived / sizeof(WCHAR)] = 0;
132 }
133 else
134 {
135 ppmi->Name[0] = 0;
136 }
137
140 &bqi, sizeof(bqi), ppmi->UniqueID, sizeof(ppmi->UniqueID),
141 &dwReceived, NULL))
142 {
143 ppmi->UniqueID[dwReceived / sizeof(WCHAR)] = 0;
144 }
145 else
146 {
147 ppmi->UniqueID[0] = 0;
148 }
149
151 if (DeviceIoControl(hDevice, IOCTL_BATTERY_QUERY_INFORMATION, &bqi, sizeof(bqi), &bi, sizeof(bi), &dwReceived, NULL))
152 {
153 RtlCopyMemory(ppmi->Chem, bi.Chemistry, sizeof(bi.Chemistry));
154 ppmi->Chem[4] = 0;
155 }
156 else
157 {
158 ppmi->Chem[0] = 0;
159 }
160
161 bws.BatteryTag = bqi.BatteryTag;
162 if (DeviceIoControl(hDevice, IOCTL_BATTERY_QUERY_STATUS, &bws, sizeof(bws), &bs, sizeof(bs), &dwReceived, NULL))
163 {
164 ppmi->ACOnline = bs.PowerState & BATTERY_POWER_ON_LINE;
165 ppmi->Charging = bs.PowerState & BATTERY_CHARGING && !(bs.PowerState & BATTERY_DISCHARGING);
166 ppmi->Critical = bs.PowerState & BATTERY_CRITICAL;
167 ppmi->BatteryLifePercent = 100 * bs.Capacity / bi.FullChargedCapacity;
168 ppmi->BatteryLifeTime = -1;
169 }
170
172 if (DeviceIoControl(
173 hDevice, IOCTL_BATTERY_QUERY_INFORMATION, &bqi, sizeof(bqi), ppmi->Manufacturer, sizeof(ppmi->Manufacturer),
174 &dwReceived, NULL))
175 {
176 ppmi->Manufacturer[dwReceived / sizeof(WCHAR)] = 0;
177 }
178 else
179 {
180 ppmi->Manufacturer[0] = 0;
181 }
182 }
183 HeapFree(GetProcessHeap(), 0, InterfaceData);
185 return TRUE;
186}
#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
@ 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 NULL
Definition: types.h:112
#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
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 SetupDiGetInterfaceDeviceDetailW
Definition: setupapi.h:2430
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W SP_DEVICE_INTERFACE_DETAIL_DATA_W
#define DIGCF_PRESENT
Definition: setupapi.h:172
struct _SP_DEVICE_INTERFACE_DATA SP_DEVICE_INTERFACE_DATA
#define DIGCF_INTERFACEDEVICE
Definition: setupapi.h:176
#define DPRINT
Definition: sndvol32.h:73
DWORD BatteryLifeTime
Definition: powermeter.c:27
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
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by PowerMeter_InitDialog(), and PowerMeterDetail_UpdateStats().

◆ PowerMeterInfo_UpdateGlobalStats()

static VOID PowerMeterInfo_UpdateGlobalStats ( PPOWER_METER_INFO  ppmi)
static

Definition at line 32 of file powermeter.c.

33{
35
36 if (GetSystemPowerStatus(&sps))
37 {
38 ppmi->ACOnline = sps.ACLineStatus != 0;
39 ppmi->Charging = sps.BatteryFlag & 8;
40 ppmi->Critical = sps.BatteryFlag & 4;
43 }
44}
BOOL WINAPI GetSystemPowerStatus(IN LPSYSTEM_POWER_STATUS PowerStatus)
Definition: power.c:27

Referenced by PowerMeter_InitDialog().

Variable Documentation

◆ hwndDlgDetail

HWND hwndDlgDetail = 0
static

Definition at line 15 of file powermeter.c.

Referenced by PowerMeterDetailDlgProc(), and PowerMeterDlgProc().

◆ SelectedBattery

int SelectedBattery = 0
static