title: Multithreaded Win32 GUI message loop
body: <p>When do you need to use this type of modified message loop in multithreaded application?</p>
  
  <pre><code>DWORD nWaitCount;
  HANDLE hWaitArray[4];
  BOOL quit;
  int exitCode;
  while (!quit)
  {
     MSG msg;
     int rc;
     rc = MsgWaitForMultipleObjects(nWaitCount, hWaitArray, FALSE, INFINITE,QS_ALLINPUT);
  
     if (rc == WAIT_OBJECT_O + nWaitCount)
     {
         while (PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE))
         {
          if (msg.message == WM_QUIT)
          {
              quit = TRUE;
              exitCode = msg.wParam;
              break;
          }
          TranslateMessage(&amp;msg);
          DispatchMessage(&amp;msg);
         }
     }
     else if (rc &gt;= WAIT_OBJECT_0 &amp;&amp; rc &lt; WAIT_OBJECT_0 + nwaitCount)
     {
         int nlndex = rc - WAIT_OBJECT_0;
     }
     else if (rc &gt;= WAIT_ABANDONED_0 &amp;&amp; rc &lt; WAIT_ABANDONED_0+ nWaitCount)
     {
         int nlndex = rc - WAIT_ABANDONED_O;
     }
  }
  </code></pre>