title: PostMessage() succeeds but my message processing code never receives the message
body: <p>In my C++ application's GUI object I have the following in the main window procedure:</p>
  
  <pre><code>case WM_SIZE:
      {
          OutputDebugString(L"WM_SIZE received.\n");
          RECT rect = {0};
          GetWindowRect(hwnd, &amp;rect);
          if (!PostMessage(0, GUI_MSG_SIZECHANGED, w, MAKELONG(rect.bottom - rect.top, rect.right - rect.left))) {
              OutputDebugString(L"PostMessage failed.\n"); // &lt;--- never called
          }
      }
  
      return 0; // break;
  </code></pre>
  
  <p>The GUI object also has the following getMessage() method:</p>
  
  <pre><code>int GUI::getMessage(MSG &amp; msg) {
      BOOL result = 0;
  
      while ((result = GetMessage(&amp;msg, 0, 0, 0)) &gt; 0) {
          if (msg.message &gt; (GUI_MSG_BASE-1) &amp;&amp; msg.message &lt; (GUI_MSG_LAST+1)) {
              OutputDebugString(L"GUI message received.\n");
              break;
          }
          else {
              TranslateMessage(&amp;msg);
              DispatchMessage(&amp;msg);
          }
      }
  
      return result;
  }
  </code></pre>
  
  <p>The application object calls this method in the following way:</p>
  
  <pre><code>while ((result = _gui.getMessage(msg)) &gt; 0) {
      switch (msg.message) {
          // TODO: Add gui message handlers
          case GUI_MSG_SIZECHANGED:
              OutputDebugString(L"GUI_MSG_SIZECHANGED received.\n");
              _cfg.setWndWidth(HIWORD(msg.lParam));
              _cfg.setWndHeight(LOWORD(msg.lParam));
              if (msg.wParam == SIZE_MAXIMIZED)
                  _cfg.setWndShow(SW_MAXIMIZE);
              else if (msg.wParam == SIZE_MINIMIZED)
                  _cfg.setWndShow(SW_MINIMIZE);
              else if (msg.wParam == SIZE_RESTORED)
                  _cfg.setWndShow(SW_SHOWNORMAL);
              break;
      }
  }
  </code></pre>
  
  <p>The application object is interested in the window size because it stores this information in a configuration file.</p>
  
  <p>When I run this in Visual Studio's debugger, the output window looks like this after resizing the window:</p>
  
  <pre><code>WM_SIZE received.
  GUI message received.
  GUI_MSG_SIZECHANGED received.
  WM_SIZE received.
  WM_SIZE received.
  WM_SIZE received.
  WM_SIZE received.
  ...etc...
  </code></pre>
  
  <p>The PostMessage() function never fails, but seems to only send GUI_MSG_SIZECHANGED (#defined as WM_APP + 0x000d) the first time WM_SIZE is handled, which is right after handling WM_CREATE.</p>
  
  <p>I have no idea what could be causing this. I tried using SendMessage and PostThreadMessage but the result is the same. Also read through MSDN's message handling documentation but couldn't find what's wrong with my code.</p>
  
  <p>Could anyone help?</p>