Skip to content

Instantly share code, notes, and snippets.

@imba-tjd
Last active February 20, 2025 11:24
Show Gist options
  • Save imba-tjd/9e8a4869d7ed5263a65e759997b53c6a to your computer and use it in GitHub Desktop.
Save imba-tjd/9e8a4869d7ed5263a65e759997b53c6a to your computer and use it in GitHub Desktop.
Show warning when battery die
// 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