Jump to content
Sign in to follow this  

Notification of the transition to standby or hibernate mode.

Recommended Posts

Jos suggested in one of the themes the following code:

#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <Date.au3>
Global $PBT_APMSUSPEND = 0x0004
Global $PBT_APMSTANDBY = 0x0005
Dim $hGUI = GUICreate("Test", 100, 100,1,1) ;You need to work without this line.
GUIRegisterMsg($WM_MOUSEWHEEL, "Standby")
Func Standby($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite(_NowTime() & ": " & $wParam & @LF)
        Case $wParam = $PBT_APMSUSPEND
            ConsoleWrite(" You going into Suspend." & @LF)
        Case $wParam = $PBT_APMRESUMESUSPEND
            ConsoleWrite(" You just woke up from Suspend." & @LF)
        Case $wParam = $PBT_APMSTANDBY
            ConsoleWrite(" You are going into Standby." & @LF)
        Case $wParam = $PBT_APMRESUMESTANDBY
            ConsoleWrite(" You just woke up from Standby." & @LF)
        Case Else

My application does not use any windows. It has only a menu in the tray. Tell me, who knows how to make this code work in my case.
Thank you!

Share this post

Link to post
Share on other sites

Well, yes, it's like an option to make a small window and not display it. But I thought there is still a code more suitable for my situation and more correct in terms of programming.

I'm very grateful to you, Jos, that you responded immediately!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By quadrplax
      I have a light bulb which I can turn on and off using UDP commands (I already have that working in AutoIt). What I would like to do is run a script before the computer goes to sleep to turn it off, and after it resumes to turn it on. I've already got the latter working, but not the former. I tried Task Scheduler with the kernel power log, but the command doesn't get executed until the computer resumes from sleep. I've tried some things using WM_POWERBROADCAST, but so far I haven't got that to work either. Here's what I've got so far:
      Global Const $WM_POWERBROADCAST = 0x218 Global Const $PBT_APMSUSPEND = 0x4 Global Const $PBT_APMRESUMEAUTOMATIC = 0x12 While 1 Sleep(100) WEnd GUICreate("Event Receiver") GUIRegisterMsg($WM_POWERBROADCAST,"MY_WM_POWERBROADCAST") Func MY_WM_POWERBROADCAST($hWnd, $uMsg, $wParam, $lParam) Switch $wParam Case $PBT_APMSUSPEND MsgBox(0,"PBT_APMSUSPEND","PBT_APMSUSPEND"&@HOUR&@MIN&@SEC) Case $PBT_APMRESUMEAUTOMATIC MsgBox(0,"PBT_APMSUSPEND","PBT_APMRESUMEAUTOMATIC"&@HOUR&@MIN&@SEC) EndSwitch EndFunc Does anyone know how to make this work?
    • By AndyS01
      I have a script that monitors network up/down time and when my laptop is set to hibernate or sleep, then later started up again, my script counts all of the hibernate/sleep time as down time.

      If I could get notification when going into hibernate/sleep mode and when it resumes normal mode, I could stop looking until normal mode is resumed.

      Is there an API that does this, or perhaps an event I could register a handler for?

  • Create New...