Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a service for Windows 7, and because of the devices I'm interacting with, I need be aware of power state changes. The only notifications I've found on MSDN for these events come through WM_POWERBROADCAST.

Now, I already know I can't recieve Windows messages in a service. Is there there any other way to become aware of this state change? I need to know if a machine is hibernating, sleeping, what-have-you, so I can avoid unexpected behavior.
Posted

1 solution

You need to use the RegisterServiceCtrlHandlerEx[^] when you register your HandlerEx[^] function.

When dwControl is SERVICE_CONTROL_POWEREVENT dwEventType provide the various PBT_ values you would receive in the wParam of a WM_POWERBROADCAST[^] event.

Best regards
Espen Harlinn
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900