Last active
February 20, 2025 11:24
-
-
Save imba-tjd/9e8a4869d7ed5263a65e759997b53c6a to your computer and use it in GitHub Desktop.
Show warning when battery die
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc battery.c -o battery.exe -Os -mwindows -Wl,--as-needed -s -nostdlib -luser32 -lkernel32 -march=native | |
#define WIN32_LEAN_AND_MEAN | |
#include <windows.h> | |
static SYSTEM_POWER_STATUS status; | |
int _main() { | |
SetProcessWorkingSetSize(GetCurrentProcess(), (SIZE_T)-1, (SIZE_T)-1); | |
while (1) { | |
GetSystemPowerStatus(&status); | |
if (status.BatteryLifePercent < 50) | |
MessageBox(NULL, "Battery below 50%", "Battery Warning", MB_SYSTEMMODAL | MB_ICONWARNING); | |
Sleep(10 * 60 * 1000); // every 10m | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment