How long since coming out of standby?

Everything else that doesn't fall into one of the other PB categories.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

How long since coming out of standby?

Post by Dude »

My app needs to know how long it's been since my PC came out of standby. Any ideas on how to test for that? Thanks.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How long since coming out of standby?

Post by netmaestro »

This page looks like it would serve. You could start counting a timer when your app receives WM_POWERBROADCAST with wParam = PBT_APMRESUMEAUTOMATIC and you'll always know how long since the last resume (sounds good on paper anyway) https://msdn.microsoft.com/en-us/librar ... s.85).aspx
BERESHEIT
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: How long since coming out of standby?

Post by Dude »

Thanks netmaestro! :) I was able to do it like this:

Code: Select all

Global awake

Procedure Callback(hWnd,Message,wParam,lParam)
  result=#PB_ProcessPureBasicEvents
  If Message=#WM_POWERBROADCAST
    Select wParam
      Case #PBT_APMRESUMESUSPEND
        awake=Date()
      Case #PBT_APMSUSPEND
        awake=0
    EndSelect
  EndIf
  ProcedureReturn result
EndProcedure

OpenWindow(0,200,200,200,100,"Time awake",#PB_Window_SystemMenu)
TextGadget(0,10,10,180,180,"")

SetWindowCallback(@Callback(),0)

Repeat
  ev=WindowEvent()
  If ev=0
    Sleep_(500)
    If awake
      SetGadgetText(0,Str(Date()-awake))
    EndIf
  EndIf
Until ev=#PB_Event_CloseWindow
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: How long since coming out of standby?

Post by Dude »

Thanks also to PureLust for this thread: http://www.purebasic.fr/english/viewtop ... 13&t=44388
Post Reply