1

I'm creating a window with CreateWindowEx for the sole purpose of receiving messages. Currently the hWndParent parameter is 0:

Result := CreateWindowEx(WS_EX_TOOLWINDOW, WindowClassName, '', WS_POPUP,
      0, 0, 0, 0, 0, 0, HInstance, nil);

I've read that a message-only window can be created by changing this parameter to HWND_MESSAGE.

Are there benefits in terms of performance and consumption of resources when using this option?

CAnder
  • 127
  • 8
  • 4
    You can use built-in `AllocateHWnd` function. Why do you want to do *this* by yourself. It's the bad place for optimization, I'd say. You're gonna make it once (for a common message receiver I hope). – TLama Sep 06 '15 at 03:04
  • @TLama: Thanks for the response. The reason is outlined here: [link](http://stackoverflow.com/questions/32322329/how-to-pass-message-to-tapartmentthread-instance-without-creating-windows-handle) – CAnder Sep 06 '15 at 04:03
  • 2
    I doubt it makes much difference – David Heffernan Sep 06 '15 at 06:47
  • 1
    Fewer resources than what? Than a TForm, or than using HWND_MESSAGE? Than TForm, absolutely yes, it will use fewer resources. Than HWND_MESSAGE who knows, and either way the difference would be absolutely tiny. – David Sep 06 '15 at 12:17
  • @TLama: although `AllocateHWnd()` is useful at times, it is also not thread-safe, and does not create a message-only window using `HWND_MESSAGE`. – Remy Lebeau Sep 06 '15 at 15:57
  • @DavidM: "*Fewer resources than what?*" - then a non-`HWND_MESSAGE` window. – Remy Lebeau Sep 06 '15 at 15:58
  • @Remy, the OP explained that by linking the other question. – TLama Sep 06 '15 at 16:00
  • @DavidHeffernan: Appreciate the response. Opinion appears to be that any difference would be negligible. Would you mind promoting your comment to an answer? Thanks. – CAnder Sep 07 '15 at 03:08

1 Answers1

2

It's hard to answer definitively. One would imagine that a message only window would be less heavy on resources than a hidden window. But who's to say that it's not the other way around? And perhaps the answer differs with OS version. You can only tell for sure by profiling.

However, you tend not to have large numbers of message only windows in a process. And so even if there's a difference, will it ever be significant? Not likely.

More important differences are to be found in behaviour. The big one is that message only windows don't receive broadcast messages.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490