views:

44

answers:

2

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?

A: 

Did you register to receive the power events?

gwell
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
Also, this function seems to be Vista+ only...
psychotik
A: 

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.

cheers, AR

Alain Rist