Skip to content

Commit

Permalink
[STOBJECT] Display the estimated battery time when hovering the batte…
Browse files Browse the repository at this point in the history
…ry icon

We do have IDS_PWR_HOURS_REMAINING and IDS_PWR_MINUTES_REMAINING string resources but they're never used programmatically.
Display the estimated battery time ONLY if the returned time is not unknown.

CORE-18969
CORE-19452
  • Loading branch information
GeoB99 committed Dec 17, 2024
1 parent b0680d6 commit 28b277a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion dll/shellext/stobject/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ typedef struct _PWRSCHEMECONTEXT
CString g_strTooltip;
static HICON g_hIconBattery = NULL;

#define HOUR_IN_SECS 3600
#define MIN_IN_SECS 60

/*++
* @name Quantize
Expand Down Expand Up @@ -78,6 +80,7 @@ static HICON DynamicLoadIcon(HINSTANCE hinst)
{
SYSTEM_POWER_STATUS PowerStatus;
HICON hBatIcon;
UINT uiHour, uiMin;
UINT index = -1;

if (!GetSystemPowerStatus(&PowerStatus) ||
Expand Down Expand Up @@ -107,7 +110,25 @@ static HICON DynamicLoadIcon(HINSTANCE hinst)
{
index = Quantize(PowerStatus.BatteryLifePercent);
hBatIcon = LoadIcon(hinst, MAKEINTRESOURCE(br_icons[index]));
g_strTooltip.Format(IDS_PWR_PERCENT_REMAINING, PowerStatus.BatteryLifePercent);

if (PowerStatus.BatteryLifeTime != BATTERY_UNKNOWN_TIME)
{
uiHour = PowerStatus.BatteryLifeTime / HOUR_IN_SECS;
uiMin = (PowerStatus.BatteryLifeTime % HOUR_IN_SECS) / MIN_IN_SECS;

if (uiHour != 0)
{
g_strTooltip.Format(IDS_PWR_HOURS_REMAINING, uiHour, uiMin, PowerStatus.BatteryLifePercent);
}
else
{
g_strTooltip.Format(IDS_PWR_MINUTES_REMAINING, uiMin, PowerStatus.BatteryLifePercent);
}
}
else
{
g_strTooltip.Format(IDS_PWR_PERCENT_REMAINING, PowerStatus.BatteryLifePercent);
}
}
else
{
Expand Down

0 comments on commit 28b277a

Please sign in to comment.