title: How to receive messages using a message-only window in a console application?
body: <p>I've created a simple Win32 console application that creates a hidden message-only window and waits for messages, the full code is below.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;Windows.h&gt;
  
  namespace {
    LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
      if (uMsg == WM_COPYDATA)
        std::cout &lt;&lt; "Got a message!" &lt;&lt; std::endl;
      return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
  }
  
  int main()
  {
    WNDCLASS windowClass = {};
    windowClass.lpfnWndProc = WindowProcedure;
    LPCWSTR windowClassName = L"FoobarMessageOnlyWindow";
    windowClass.lpszClassName = windowClassName;
    if (!RegisterClass(&amp;windowClass)) {
      std::cout &lt;&lt; "Failed to register window class" &lt;&lt; std::endl;
      return 1;
    }
    HWND messageWindow = CreateWindow(windowClassName, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, 0);
    if (!messageWindow) {
      std::cout &lt;&lt; "Failed to create message-only window" &lt;&lt; std::endl;
      return 1;
    }
  
    MSG msg;
    while (GetMessage(&amp;msg, 0, 0, 0) &gt; 0) {
      TranslateMessage(&amp;msg);
      DispatchMessage(&amp;msg);
    }
    return msg.wParam;
  }
  </code></pre>
  
  <p>However, I'm not receiving any messages from another application. <code>GetMessage()</code> just blocks and never returns. I use <code>FindWindowEx()</code> with the same class name in the application that sends a message, and it finds the window. Just the message is apparently never being received.</p>
  
  <p>Am I doing something wrong here? What is the most minimal application that can receive window messages?</p>