Page 1 of 1

How long since coming out of standby?

Posted: Sun Dec 24, 2017 11:11 pm
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.

Re: How long since coming out of standby?

Posted: Sun Dec 24, 2017 11:51 pm
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

Re: How long since coming out of standby?

Posted: Mon Dec 25, 2017 1:11 am
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

Re: How long since coming out of standby?

Posted: Mon Dec 25, 2017 1:12 am
by Dude
Thanks also to PureLust for this thread: http://www.purebasic.fr/english/viewtop ... 13&t=44388