Detecting suspend/hibernate [Resolved]
Detecting suspend/hibernate [Resolved]
Hi can I detect that a PC is about to suspend or hibenate ?
Thanks.
Thanks.
Last edited by zoot33 on Tue Nov 23, 2010 12:18 pm, edited 1 time in total.
Re: Detecting suspend/hibernate
I'm not sure if I get your concern right.
But if you're looking for the system idle time, the following code may help:Greetz, PL.
But if you're looking for the system idle time, the following code may help:
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
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
Re: Detecting suspend/hibernate
Thanks. 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 this is about to happen.
Last edited by zoot33 on Tue Nov 23, 2010 11:04 am, edited 1 time in total.
Re: Detecting suspend/hibernate
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.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
Re: Detecting suspend/hibernate
no problem, thanks for your help.
Re: Detecting suspend/hibernate
I assume, that the PBT_APMSUSPEND Event will be the thing you're looking for.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
Re: Detecting suspend/hibernate
I think it might be, do you have any examples of its use ?
Re: Detecting suspend/hibernate
seems like i need to register my app to be able to receive those events
Re: Detecting suspend/hibernate
So far ... NO.zoot33 wrote:... , do you have any examples of its use ?
But I did not see a reason why I shouldn't write one:
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
Greetz, PL.
Last edited by PureLust on Tue Nov 23, 2010 12:46 pm, edited 3 times in total.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
Re: Detecting suspend/hibernate
thanks PL - it works great !
Re: Detecting suspend/hibernate [Resolved]
Little improvement, with "Awaken from Suspend" detection (see code above).
(I hope, "Awaken from Suspend" is nearly right spelling. )
[Edit:] Maybe this Thread would be right placed in Tricks 'n' Tips now.
(I hope, "Awaken from Suspend" is nearly right spelling. )
[Edit:] Maybe this Thread would be right placed in Tricks 'n' Tips now.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)