How to get the Windows Power State Message (WM_POWERBROADCAST) when not running a Win32 GUI app?

前端 未结 3 1246
余生分开走
余生分开走 2021-01-06 12:46

So basically I have a plugin dll that is loaded by a GUI-Application. In this dll I need to detect when Windows enters the Hibernate state. I cannot modify the GUI-App. GetM

3条回答
  •  鱼传尺愫
    2021-01-06 13:37

    I ran into a similar problem with a Windows console application. I wrote up a blog post on what the issues are, how the hidden window seems like the only solution, and how to do it. The post is available here and the source code is available here. The basic principle I used is almost identical to Indeera's answer.

    I'm not sure if you would have to modify my solution at all to run in a DLL. I believe that ALL threads which have a message queue (and a thread does when it creates a window) receive WM_POWERBROADCAST messages, so spooling up one of your own even if you are loaded by a Windows application might work.

    It's worth noting by the way, that you aren't guaranteed to receive a notification prior to the system going into Hibernate (such as from a critical battery state) or any other sleep state for that matter. You will however receive a PBT_APMRESUMEAUTOMATIC event (or PBT_APMRESUMECRITICAL on systems prior to Vista) when the system comes back online after such an event has occurred.

提交回复
热议问题