title: Will GetMessage() return -1 in main message loop?
body: <p>According to the <a href="http://msdn.microsoft.com/en-us/library/ms644936%28VS.85%29.aspx" rel="nofollow">GetMessage API</a> from MSDN Library, it might returns -1 when there is an error. The document provides a code snippet of common error that should be avoid:</p>
  
  <pre><code>while (GetMessage( lpMsg, hWnd, 0, 0)) ...
  </code></pre>
  
  <p>Document says:</p>
  
  <blockquote>
    <p>The possibility of a -1 return value
    means that such code can lead to fatal
    application errors. Instead, use code
    like this:</p>
  </blockquote>
  
  <pre><code>BOOL bRet;
  while( (bRet = GetMessage( &amp;msg, hWnd, 0, 0 )) != 0)
  { 
      if (bRet == -1)
      {
          // handle the error and possibly exit
      }
      else
      {
          TranslateMessage(&amp;msg); 
          DispatchMessage(&amp;msg); 
      }
  }
  </code></pre>
  
  <p>My question is, in every sample code, including default application created from Visual Studio, from Microsoft, the main message loop looks like below:</p>
  
  <pre><code>while (GetMessage(&amp;msg, NULL, 0, 0))
  {
      TranslateMessage(&amp;msg);
      DispatchMessage(&amp;msg);
  }
  </code></pre>
  
  <p>Notice that the 2nd parameter of GetMessage above is NULL. If the code above is valid, does this mean that GetMessage here will NEVER returns -1 so that dealing with return value of -1 is not necessary?</p>