title: Win32 Message Loops: Quitting after window closes with GetMessage(&msg, NULL, 0, 0)?
body: <p>If I have the following code below, how do I detect when the window has been closed, so I can quit? <code>r</code> never seems to get the value <strike><code>-1</code></strike> <code>0</code>, and I need to process messages for the entire thread, not just the current window.</p>
  
  <pre><code>HWND hWnd = CreateWindowExW(0, L"Edit", L"My Window", WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, CW_USEDEFAULT, 300, 200, NULL, NULL, NULL, NULL);
  ShowWindow(hWnd, SW_SHOWDEFAULT);
  MSG msg;
  BOOL r;
  while ((r = GetMessageW(&amp;msg, NULL, 0, 0)) != 0)
  {
      if (r == -1) { break; }
      TranslateMessage(&amp;msg);
      DispatchMessageW(&amp;msg);
  }
  </code></pre>