title: How to hide a window, instead of exiting, when the top right cross button is pressed?
body: <p>By default, a standard window created with:</p>
  
  <pre><code>HWND hwnd = CreateWindowEx(0, CLASS_NAME, L"Test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
  ShowWindow(hwnd, nCmdShow);
  </code></pre>
  
  <p>will be closed, causing the program to exit, when we click on the top right cross:</p>
  
  <p><a href="https://i.stack.imgur.com/1TFuo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1TFuo.png" alt="enter image description here"></a></p>
  
  <p>My program has a single such window, but also an always-present icon in the <strong>system tray notification area</strong>.</p>
  
  <p><strong>How to make that clicking on the top right cross makes this window hidden, but does not exit the program?</strong></p>
  
  <p>This didn't work in the main window message loop, the app is still exiting.</p>
  
  <pre><code>switch (msg) 
  {
      case WM_CLOSE:
          ShowWindow(hWnd, SW_HIDE);
          break;
  }
  </code></pre>