Detecting suspend/hibernate [Resolved]
Posted: Tue Nov 23, 2010 10:12 am
Hi can I detect that a PC is about to suspend or hibenate ?
Thanks.
Thanks.
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
EnableExplicit
Structure LASTINPUTINFO
cbSize.l
dwTime.l
EndStructure
Define Event
Define LastInput.LASTINPUTINFO
LastInput\cbSize = SizeOf(LASTINPUTINFO)
If OpenWindow(0,0,0,200,100,"User Idletime",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
AddWindowTimer(0,0,100)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Timer
GetLastInputInfo_(@LastInput)
Debug "IdleTime: " + Str(ElapsedMilliseconds() - LastInput\dwTime) + " ms"
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
So I didn't get it right, the first time, sorry.zoot33 wrote:When a user decides to put their PC in standby, I want to do some stuff in my application before the PC goes to sleep. Therefore I need to detect when the PC is about to check out.
So far ... NO.zoot33 wrote:... , do you have any examples of its use ?
Code: Select all
; Suspend-Mode detection example.
; By Albert Cremers, (aka PureLust at PureBasic Forum) - 23.11.2010
EnableExplicit
Define Event
#PBT_APMQUERYSUSPEND = $00
#PBT_APMSUSPEND = $04
#PBT_APMRESUMESUSPEND = $07
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
Protected Counter
If uMsg = #WM_POWERBROADCAST
Select wParam
Case #PBT_APMQUERYSUSPEND
Debug "Permission for Suspend requested ..."
Case #PBT_APMSUSPEND
Debug "Entering Suspend-Mode ..."
Beep_(1350,200)
Delay(20)
Beep_(900,400)
Case #PBT_APMRESUMESUSPEND
Debug "Awaken from Suspend"
Delay(3000)
Beep_(900,200)
Delay(20)
Beep_(1350,400)
EndSelect
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(0,0,0,200,100,"Waiting for Suspend-Mode ...",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowCallback(@WinCallback())
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf