Note that there are some explanatory texts on larger screens.

plurals
  1. POPostMessage only works once?
    text
    copied!<p>I'm trying to send a message from a global WindowProc function to a GUI class. The message is defined as follows:</p> <pre><code>#define WM_ENV_RESIZED (WM_APP + 0) </code></pre> <p>My WindowProc function looks like this</p> <pre><code>LRESULT CALLBACK windowProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int res; switch (message) { case WM_SIZE: std::cout &lt;&lt; "window resized" &lt;&lt; std::endl; res = PostMessage(hWnd, WM_ENV_RESIZED, 0, 0); if ( res == 0 ) //&lt;-- res is never 0 { std::cout &lt;&lt; "PostMessage failure!" &lt;&lt; std::endl; std::cout &lt;&lt; "Error code: " &lt;&lt; GetLastError() &lt;&lt; std::endl; } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return DefWindowProc(hWnd, message, wParam, lParam); } </code></pre> <p>The message is then received in the GUI class like so:</p> <pre><code>MSG msg; while (running) { while ( PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE) ) processWindowsMessage(&amp;msg); //DirectX render calls } </code></pre> <p>Now my problem is that the message is never received by PeekMessage(). It is only received once when the window is created. After that is it never received.</p> <p>Calling GetLastError() directly after PostMessage() always returns error code 6, which stands for ERROR_INVALID_HANDLE according to <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx" rel="nofollow">MSDN</a>. But this doesn't make any sense, because PostMessage() never returns 0, which means something went wrong during posting. I have tried bypassing the message queue and using SendMessage() to send the message directly to the window, but that always returns 0 (with the same error code 6..).</p> <p>I really have no idea what I'm doing wrong. How can I make sure a posted message is always received when using PeekMessage()?</p> <p><strong>EDIT:</strong> I've updated the message loop as Remy suggested. Below is the code in processWindowsMessage()</p> <pre><code>void Environment::processWindowsMessage( MSG *msg ) { switch ( msg-&gt;message ) { case WM_ENV_RESIZED: std::cout &lt;&lt; "WM_ENV_RESIZED caught" &lt;&lt; std::endl; break; case WM_QUIT: running = false; break; default: TranslateMessage(msg); DispatchMessage(msg); break; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload