BBC BASIC for Windows
Programming >> Operating System >> Laptop Charge
http://bb4w.conforums.com/index.cgi?board=os&action=display&num=1301745178

Laptop Charge
Post by JB91 on Apr 2nd, 2011, 11:52am

I wasn't sure which category to put this in, but how would you be able to get the current level of charge on a laptop?

Josh.
Re: Laptop Charge
Post by admin on Apr 2nd, 2011, 5:42pm

on Apr 2nd, 2011, 11:52am, JB91 wrote:
I wasn't sure which category to put this in, but how would you be able to get the current level of charge on a laptop?

Check out the CallNtPowerInformation API:

http://msdn.microsoft.com/en-us/library/aa372675.aspx

The SystemBatteryState information level seems to be what you need:

http://msdn.microsoft.com/en-us/library/aa373212.aspx

Richard.
Re: Laptop Charge
Post by JB91 on Apr 3rd, 2011, 09:28am

Can you provide an example program, because whenevre I do it, it seems to fail... huh
Re: Laptop Charge
Post by admin on Apr 3rd, 2011, 2:23pm

on Apr 3rd, 2011, 09:28am, JB91 wrote:
Can you provide an example program, because whenevre I do it, it seems to fail... huh

I can't see anything particularly difficult that might be causing your problem; it appears to be a straightforward API to use. Do make sure you adhere to the MSDN documentation in every detail.

The only pitfall I can see which might possibly trip you up is that the Spare1[4] in the SYSTEM_BATTERY_STATE structure must be converted to Spare1%(3) in BBC BASIC, because the suffix is the maximum value of the subscript not the number of elements.

If you're still having problems, post the code which is failing.

Re: Laptop Charge
Post by JB91 on Apr 3rd, 2011, 2:34pm

It works now!
Thanks! wink