Reputation: 4097
I am writing an native c++ application that needs to do a quick bit of work if the Windows 7 system is put into sleep mode---otherwise it will unavoidably crash when the system wakes up.
What is the easiest way to register for a system event (suspend) using native c++?
I really just want to do what these guys do but I have an arbitrary class (not a gui) that I would like to have setup an event handler and get the PBT_APMSUSPEND event and I'm not sure the easiest way to do this.
Autoitscript apparently has a nice way where you can write
GUICreate("Event Receiver")
GUIRegisterMsg($WM_POWERBROADCAST,"MY_WM_CALLBACKFUNCTION")
and I was hoping to have something similarly easy.... without a full-on message pump setup.
Upvotes: 0
Views: 517
Reputation: 595712
Simply create a hidden window using CreateWindow/Ex()
and have its window procedure callback process WM_POWERBROADCAST
messages. You don't need to create a GUI app in order to create windows.
Upvotes: 4