Question

I have an ATL app where I want to handle WM_POWERBROADCAST. I have a CMainDlg (CAxDialogImpl) in whose MSG_MAP I defined the handler.

BEGIN_MSG_MAP(CMainDlg)
    ...
    MESSAGE_HANDLER(WM_POWERBROADCAST, OnPowerChange)
    ...
END_MSG_MAP()

However, the handler isn't invoked when I do things that should invoke it, for instance change power settings or put the machine to sleep.

Any ideas about what might be going on, and how to fix this? Does CMainDlg not get notified of power events, for some reason?

Was it helpful?

Solution

I suspect your dialog not being a top level window (WS_POPUP styled).

Just tested with a WTL AppWizard non modal dialog app that WM_POWERBROADCAST is received (without any registration) on AC plugged/unplugged.

OTHER TIPS

Did you register to receive the power events?

To add to answers above, you might want to use Spy++ tool to make sure the messages of interest are posted to your application in first place. You will also see which windows they are posted to, and if it is your window where you are waiting for this message.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top