//================================================= file = getBattery.c ===== //= Program to get remaining battery life (percent) of a Windows laptop = //=========================================================================== //= Notes: = //= 1) See http://msdn.microsoft.com/en-us/library/aa372693(v=VS.85).aspx = //=-------------------------------------------------------------------------= //= Build: bcc32 getBattery.c = //=-------------------------------------------------------------------------= //= Execute: getBattery = //=-------------------------------------------------------------------------= //= Author: Ken Christensen = //= University of South Florida = //= WWW: http://www.csee.usf.edu/~christen = //= Email: christen@csee.usf.edu = //=-------------------------------------------------------------------------= //= History: KJC (01/01/11) - Genesis = //=========================================================================== //----- Include files ------------------------------------------------------- #include // Needed for printf() #include // Needed for Windows stuff //=========================================================================== //= Main program = //=========================================================================== int main() { SYSTEM_POWER_STATUS *powerStruc; // Windows structure int flag; // Flag for successful command int percentLeft; // Battery percent left // Create space for powerStruc powerStruc = malloc(sizeof(SYSTEM_POWER_STATUS)); // Issue the Get command flag = GetSystemPowerStatus(powerStruc); printf("Return flag = %d \n", flag); // Grap the batter life left and output it percentLeft = powerStruc->BatteryLifePercent; printf("Battery percent left = %d %% \n", percentLeft); return(0); }