Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Power API

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary''s Student - 25 Jan 2008 13:29 GMT
I am building an Excel alarm clock for a laptop.  I am updating the display
with an  OnTime event.  One of the requirements is to autonomously detect if
the laptop switches from A/C power to its internal battery.

Has anyone come across an API that will return the power state? Say TRUE if
A/C, FALSE if battery?

Thanks for any leads.
Signature

Gary''s Student - gsnu200766

John Bundy - 25 Jan 2008 14:29 GMT
Sorry i don't know who to give credit to as i found this some time ago and
modified it. Enjoy!

Declare Function GetSystemPowerStatus& Lib "kernel32" (lpSystemPowerStatus
As _
SYSTEM_POWER_STATUS)

Type SYSTEM_POWER_STATUS
ACLineStatus As Byte
BatteryFlag As Byte
BatteryLifePercent As Byte
Reserved1 As Byte
BatteryLifeTime As Long
BatteryFullLifeTime As Long
End Type

Public SysStat As SYSTEM_POWER_STATUS
Public Ret As Boolean
'***************************
' Place in command button click
Private Sub Command1_Click()
Ret = GetSystemPowerStatus&(SysStat)
MsgBox Ret
MsgBox "AC Status = " & SysStat.ACLineStatus
End Sub
'*****************************

Ret is True if successful.
ACLineStatus =0 if offline (battery?), 1 if online (AC Power, also desktop),
255 if unknown (Aliens?)

Signature

-John
Please rate when your question is answered to help us and others know what
is helpful.

> I am building an Excel alarm clock for a laptop.  I am updating the display
> with an  OnTime event.  One of the requirements is to autonomously detect if
[quoted text clipped - 4 lines]
>
> Thanks for any leads.
Jim Cone - 25 Jan 2008 14:32 GMT
Maybe...

Private Declare Function GetDevicePowerState Lib "kernel32.dll" _
  (ByVal hDevice As Long, ByRef pfOn As Long) As Long
http://msdn2.microsoft.com/en-us/library/aa372690.aspx

Private Declare Function GetSystemPowerStatus Lib "kernel32.dll" _
  (ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
http://msdn2.microsoft.com/en-us/library/aa372693(VS.85).aspx

Signature

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"Gary''s Student"
wrote in message
I am building an Excel alarm clock for a laptop.  I am updating the display
with an  OnTime event.  One of the requirements is to autonomously detect if
the laptop switches from A/C power to its internal battery.

Has anyone come across an API that will return the power state? Say TRUE if
A/C, FALSE if battery?
Thanks for any leads.
--
Gary''s Student - gsnu200766

Gary''s Student - 25 Jan 2008 14:46 GMT
Thank Jim (once again) !
Signature

Gary''s Student - gsnu200766

> Maybe...
>
[quoted text clipped - 5 lines]
>    (ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
> http://msdn2.microsoft.com/en-us/library/aa372693(VS.85).aspx
John Bundy - 25 Jan 2008 14:34 GMT
Actually this looks to be the link and it contains some more info, about 2/3
the way down.

http://www.codeguru.com/forum/archive/index.php/t-199354.html
Signature

-John
Please rate when your question is answered to help us and others know what
is helpful.

> I am building an Excel alarm clock for a laptop.  I am updating the display
> with an  OnTime event.  One of the requirements is to autonomously detect if
[quoted text clipped - 4 lines]
>
> Thanks for any leads.
Gary''s Student - 25 Jan 2008 14:46 GMT
Thanks John!!
Signature

Gary''s Student - gsnu200766

> Actually this looks to be the link and it contains some more info, about 2/3
> the way down.
[quoted text clipped - 9 lines]
> >
> > Thanks for any leads.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.