Hello, all.
I am brand new to C++. I am trying to write a quick app to shut off a Pocket PC(WM 2003) once the battery reaches 15% . I believe I have all of the code that i need (which I found in various places), but I am not quite grasping exactly how to use the API code, which I have pasted below.
Can some explain how to code: "SWITCH OFF POCKET PC IF BATTERY PERCENT <15%"
:::CODE TO SWITCH OFF POCKET PC:::
Code:
// Switch off a Pocket PC
//
#include "stdafx.h"
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// Send keypresses that mean power off
keybd_event(VK_OFF,0,KEYEVENTF_SILENT,0);
keybd_event(VK_OFF,0,(KEYEVENTF_KEYUP|KEYEVENTF_SILENT),0);
return 0;
}
------------
:::API CODE THAT RETURNS BATTERY PERCENT (SO I AM TOLD BY HELP FILE):::
API REFERNCE:
SYSTEM_POWER_STATUS_EX
This structure contains information about the power status of the system.
Code:
typedef struct _SYSTEM_POWER_STATUS_EX {
BYTE ACLineStatus;
BYTE BatteryFlag;
BYTE BatteryLifePercent;
BYTE Reserved1;
DWORD BatteryLifeTime;
DWORD BatteryFullLifeTime;
BYTE Reserved2;
BYTE BackupBatteryFlag;
BYTE BackupBatteryLifePercent;
BYTE Reserved3;
DWORD BackupBatteryLifeTime;
DWORD BackupBatteryFullLifeTime;
} SYSTEM_POWER_STATUS_EX, *PSYSTEM_POWER_STATUS_EX, *LPSYSTEM_POWER_STATUS_EX;
ADDITIONAL CODE I MAY NEED???:
This function retrieves the power status of the system. The status indicates whether the system is running on AC or DC power, whether or not the batteries are currently charging, and the remaining life of main and backup batteries.A remote application interface (RAPI) version of this function exists, and it is called CeGetSystemPowerStatusEx.
Code:
BOOL GetSystemPowerStatusEx(
PSYSTEM_POWER_STATUS_EX pstatus,
BOOL fUpdate );
Parameters
pstatus[out] Pointer to the SYSTEM_POWER_STATUS_EX structure receiving the power status information.
fUpdate
[in] If this Boolean is set to TRUE, GetSystemPowerStatusEx gets the latest information from the device driver, otherwise it retrieves cached information that may be out-of-date by several seconds.
Thank you in advance