It is currently Wed Sep 30, 2020 10:37 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How long since coming out of standby?
PostPosted: Sun Dec 24, 2017 11:11 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: How long since coming out of standby?
PostPosted: Sun Dec 24, 2017 11:51 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8143
Location: Fort Nelson, BC, Canada
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/library/windows/desktop/aa373247(v=vs.85).aspx

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: How long since coming out of standby?
PostPosted: Mon Dec 25, 2017 1:11 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
Thanks netmaestro! :) I was able to do it like this:

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: How long since coming out of standby?
PostPosted: Mon Dec 25, 2017 1:12 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
Thanks also to PureLust for this thread: viewtopic.php?f=13&t=44388


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye