https://git.reactos.org/?p=reactos.git;a=commitdiff;h=28b277aa42dd7d8d156e5cacab144b197e278434

commit 28b277aa42dd7d8d156e5cacab144b197e278434
Author:     George Bișoc <[email protected]>
AuthorDate: Sun Dec 15 20:58:18 2024 +0100
Commit:     George Bișoc <[email protected]>
CommitDate: Tue Dec 17 14:34:30 2024 +0100

    [STOBJECT] Display the estimated battery time when hovering the battery 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
---
 dll/shellext/stobject/power.cpp | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/dll/shellext/stobject/power.cpp b/dll/shellext/stobject/power.cpp
index ecae456b66e..7f714cf6253 100644
--- a/dll/shellext/stobject/power.cpp
+++ b/dll/shellext/stobject/power.cpp
@@ -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
@@ -78,6 +80,7 @@ static HICON DynamicLoadIcon(HINSTANCE hinst)
 {
     SYSTEM_POWER_STATUS PowerStatus;
     HICON hBatIcon;
+    UINT uiHour, uiMin;
     UINT index = -1;
 
     if (!GetSystemPowerStatus(&PowerStatus) ||
@@ -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
     {

Reply via email to