0

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?

psychotik
  • 38,153
  • 34
  • 100
  • 135

3 Answers3

0

Did you register to receive the power events?

gwell
  • 2,695
  • 20
  • 20
  • Ah, so it seems like I need to do this for settings changes. What if I'm only interested in PBT_APMSUSPEND? Documentation seems to suggest that I should receive WM_POWERBROADCAST but I don't. Do you know? – psychotik Mar 08 '10 at 23:38
0

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.

Alain Rist
  • 827
  • 6
  • 11
0

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.

Roman R.
  • 68,205
  • 6
  • 94
  • 158