Log in

View Full Version : eVC++: How to get battery status?


PPCdev
02-11-2003, 10:04 PM
Not covered in the books, how would I go about getting the battery status of my PPC in eVC++?

Thanks-

mel
02-11-2003, 10:30 PM
Have you looked in the eVC help file?

PPCdev
02-11-2003, 11:52 PM
typedef struct _SYSTEM_POWER_STATUS_EX2 {
BYTE ACLineStatus;
BYTE BatteryFlag;
BYTE BatteryLifePercent;
BYTE Reserved1;
DWORD BatteryLifeTime;
DWORD BatteryFullLifeTime;
BYTE Reserved2;
BYTE BackupBatteryFlag;
BYTE BackupBatteryLifePercent;
BYTE Reserved3;
DWORD BackupBatteryLifeTime;
DWORD BackupBatteryFullLifeTime;
WORD BatteryVoltage;
DWORD BatteryCurrent;
DWORD BatteryAverageCurrent;
DWORD BatteryAverageInterval;
DWORD BatterymAHourConsumed;
DWORD BatteryTemperature;
DWORD BackupBatteryVoltage;
BYTE BatteryChemistry;
} SYSTEM_POWER_STATUS_EX2, *PSYSTEM_POWER_STATUS_EX2, *LPSYSTEM_POWER_STATUS_EX2;


I have this, but I dont know what to do with it. A sample or snippit would help, mind you Im still learning C structure. :-(

Thank you for looking.

mel
02-12-2003, 02:18 AM
<ignore>

mel
02-12-2003, 02:20 AM
Before you can do advanced stuff, I suggest you familiarize yourself with the C++ language, classes, structures, Win32 API's, using MSDN documentation etc. Don't rush into writing advanced commercial style programs. Start small...make a structure that stores a name and phone number, pass it to a function as a pointer, learn how unicode strings are manipulated etc. You can't write good, stable software by copying and pasting code snippets. And you can't expect to always find a code snippet for every task - some of it needs to be hand coded!

Anyway, look up the GetSystemPowerStatusEx API. Good luck!

EvilOne
02-12-2003, 04:06 AM
int nBattValue = 0;
BOOL fCharging = FALSE;
SYSTEM_POWER_STATUS_EX sps;

// Fill the SYSTEM_STATUS_EX struct with some meaningful information
GetSystemPowerStatusEx(&sps, TRUE);

// Get the battery percentage left/available
nBattValue = sps.BatteryLifePercent;

// Let's see if the battery is charging or not
if(sps.BatteryFlag & 0x08)
fCharging = TRUE;
else
fCharging = FALSE;


Also, see the online help entitled "SYSTEM_POWER_STATUS_EX" for a description of fields and other flags. And of course you can use SYSTEM_STATUS_EX2 instead of SYSTEM_STATUS_EX like I did.

Some other places, other than here, that may help you are:

newsgroups (msnews.microsoft.com):
[] microsoft.public.de.german.windowsce
[] microsoft.public.de.german.windowsce.entwickler
[] microsoft.public.win32.programmer.wince
[] microsoft.public.windowsce.app.development

Some other websites:
http://www.pocketpcdn.com/
http://www.pocketpccode.com/

EvilOne
02-12-2003, 04:06 AM
int nBattValue = 0;
BOOL fCharging = FALSE;
SYSTEM_POWER_STATUS_EX sps;

// Fill the SYSTEM_STATUS_EX struct with some meaningful information
GetSystemPowerStatusEx(&sps, TRUE);

// Get the battery percentage left/available
nBattValue = sps.BatteryLifePercent;

// Let's see if the battery is charging or not
if(sps.BatteryFlag & 0x08)
fCharging = TRUE;
else
fCharging = FALSE;


Also, see the online help entitled "SYSTEM_POWER_STATUS_EX" for a description of fields and other flags. And of course you can use SYSTEM_STATUS_EX2 instead of SYSTEM_STATUS_EX like I did.

Some other places, other than here, that may help you are:

newsgroups (msnews.microsoft.com):
[] microsoft.public.de.german.windowsce
[] microsoft.public.de.german.windowsce.entwickler
[] microsoft.public.win32.programmer.wince
[] microsoft.public.windowsce.app.development

Some other websites:
http://www.pocketpcdn.com/
http://www.pocketpccode.com/

EvilOne
02-12-2003, 04:07 AM
int nBattValue = 0;
BOOL fCharging = FALSE;
SYSTEM_POWER_STATUS_EX sps;

// Fill the SYSTEM_STATUS_EX struct with some meaningful information
GetSystemPowerStatusEx(&sps, TRUE);

// Get the battery percentage left/available
nBattValue = sps.BatteryLifePercent;

// Let's see if the battery is charging or not
if(sps.BatteryFlag & 0x08)
fCharging = TRUE;
else
fCharging = FALSE;


Also, see the online help entitled "SYSTEM_POWER_STATUS_EX" for a description of fields and other flags. And of course you can use SYSTEM_STATUS_EX2 instead of SYSTEM_STATUS_EX like I did.

EvilOne
02-12-2003, 04:07 AM
int nBattValue = 0;
BOOL fCharging = FALSE;
SYSTEM_POWER_STATUS_EX sps;

// Fill the SYSTEM_STATUS_EX struct with some meaningful information
GetSystemPowerStatusEx(&sps, TRUE);

// Get the battery percentage left/available
nBattValue = sps.BatteryLifePercent;

// Let's see if the battery is charging or not
if(sps.BatteryFlag & 0x08)
fCharging = TRUE;
else
fCharging = FALSE;


Also, see the online help entitled "SYSTEM_POWER_STATUS_EX" for a description of fields and other flags. And of course you can use SYSTEM_STATUS_EX2 instead of SYSTEM_STATUS_EX like I did.

EvilOne
02-12-2003, 04:25 AM
Ok, only meant to post the first response that I made.. What ever happened to the ability to delete your own posts? What is more interesting, is that I can ONLY delete this message and not the others that I posted. Sorry everyone. I dunno what happened with the site/system.

PPCdev
02-12-2003, 04:43 AM
Mel, good advice sir. I do need to work more on the basics, but I am larning that though writing some simple programs that perform one specific task, not a big project that 'does it all', Lord knows Im not ready for that! The code snippits are *never* for copy and paste, only so I can examine how the statements are used, and other needed commands to make it work. It reminds me of when I first started learning to program, the best teacher was other's code, as Id think most coders would agree. :-)

Evil, thanks for the sample, its not greatly deatailed, but thats what beginners like me want, just enough to understand but not so much to get confused! Im learning quite a bit from response to questions and the book I got, Visual C++ .NET Step by Step, is just a tad above my abilities to understand it all, but its slowly sinking in. Coming from VB, theres a lot of C structure that needs to be understood before you can really hack out some code as you well know, so I got my plate full trying to make progress.

The only real thing I know for sure, Im glad to be getting away from VB and into VC!


Thanks for all the excelent advice and help!
Andrew

dangerwit
02-19-2003, 05:53 PM
...this is precisely what I've been working on recently. I've used, for example:

GetSystemPowerStatusEx2(&pStruct, sizeof(pStruct), TRUE);

...where pStruct is simply

SYSTEM_POWER_STATUS_EX2 pStruct;

This seems to return tons of good data. Oh, and I access it like this:

return pStruct.BatterymAHourConsumed;

...as an example. :)

*Phil