How to detect Windows hibernation mode?

Windows specific forum
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

How to detect Windows hibernation mode?

Post by Marc56us »

WM_QUERYENDSESSION detects the end of the session, but is it possible to detect the Windows hibernation ?

The reason: I would like to be able to stop the web radio and/or MP3 play of my programs when the user clicks on Hibernation mode (Hibernation mode launch by Windows or by command: rundll32.exe powrprof.dll,SetSuspendState 1,0,1) Otherwise, the music will immediately resume from deep sleep.

:wink:
Last edited by Marc56us on Sun Mar 08, 2020 10:04 am, edited 2 times in total.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: How to detect Windows hibernation mode?

Post by RSBasic »

Code: Select all

EnableExplicit

Procedure WinCallback(hWnd, uMsg, wParam, lParam) 
  
  Select uMsg 
    Case #WM_POWERBROADCAST 
      Select wParam
        Case #PBT_APMSUSPEND
          Debug "PC now goes into hibernation."
          
      EndSelect
  EndSelect 
  
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  SetWindowCallback(@WinCallback())
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Image
Image
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: How to detect Windows hibernation mode?

Post by Marc56us »

Thank you RSBasic, it works perfectly now 8)

:idea: A subsidiary question: Is there a way to interrupt (or pause some seconds) the start of this sleep mode while something is displayed?
:?: Maybe cancel the standby request completely, continue the program, then launch the software standby?
But I don't think Windows allows software to interrupt a stop command (as you can do under unix with shutdown)

(Put in extended sleep mode by command, I know how to do it with runprogram and rundll32.exe powrprof.dll,SetSuspendState 1,0,1)
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: How to detect Windows hibernation mode?

Post by Bitblazer »

In the past you could return #PWR_FAIL to abort the suspend, do stuff and later init suspend again. But it might not work with #WM_POWERBROADCAST anymore.
webpage - discord chat links -> purebasic GPT4All
Post Reply