3

I'm trying to find out whether broadcast messages will be sent to message only windows, i.e. created as:

hWnd = CreateWindow(MAKEINTATOM(RegisterClass(&wnd)), NULL, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, hInstance, 0);

Thing is that I don't get any broadcast messages to that window... ;)

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Robert
  • 2,330
  • 29
  • 47
  • Are you saying that you don't get *any* broadcast messages, or just that you don't get `WM_POWERBROADCAST`? – Cody Gray - on strike May 04 '11 at 14:09
  • I don't get the WM_QUERYENDSESSION message either. Thing is that I've read somewhere that HWND_MESSAGE windows don't receive OS broadcasts, and that you'd need a toplevel window for that. But I haven't found any documentation to support/debunk this... – Robert May 04 '11 at 14:19

1 Answers1

4

Your suspicions are correct. Message-only windows (those created by specifying HWND_MESSAGE for the hwndParent parameter of the CreateWindowEx function) do not receive broadcast notifications:

A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.

Reference: MSDN

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • RegisterPowerSettingNotification is Vista and later, this problem is on XP ;) – Robert May 04 '11 at 14:17
  • @Robert: Yup, no problem. Sorry it wasn't answer you were hoping for. ;-) But it's always good to get confirmation from the docs. Just create a top-level window, but without the `WS_VISIBLE` style. – Cody Gray - on strike May 04 '11 at 14:36