I have a Windows application that monitors Windows power management events
How to manually send such events to the process for testing purposes rather than putting the laptop to sleep or hibernate? Is there a way to post PBT_APMSUSPEND to a process for example?
You can send the message, with the parameters set up accordingly, using SendMessage
, using the recipient applications main window handle as target.
You might have problems with PBT_POWERSETTINGCHANGE
, where lParam
is a pointer to a structure. (Windows usually copies such structures to other processes accordingly, but as this is a message you are not supposed to send yourself, it might be handled differently.)
It would be more prudent anyway to test the real scenario, e.g. in a virtual machine. While you can test your applications response to a particular message, there are aspects this does not cover
RegisterPowerSettingNotification
)