title: c++ / application with multiple separate windows
body: <p>So i have this code that creates two windows:</p>
  
  <pre><code>WNDCLASS wc;
      wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW;
      wc.lpfnWndProc = StaticWndProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = (HINSTANCE)GetModuleHandle(nullptr);
      wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
      wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 
      wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
      wc.lpszMenuName = nullptr;
      wc.lpszClassName = _T("Move Engine");
      RegisterClass(&amp;wc);
      m_hWnd = CreateWindow("Move Engine", "Move Engine", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, usWidth, usHeight, nullptr, nullptr, wc.hInstance, this);
  
      // Create the settings window
      wc.lpszClassName = _T("Settings");
      RegisterClass(&amp;wc);
      s_hWnd = CreateWindow("Settings", "Settings", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 20, nullptr, nullptr, wc.hInstance, this);
  
  ShowWindow(m_hWnd, SW_SHOW);
  ShowWindow(s_hWnd, SW_SHOW);
  </code></pre>
  
  <p>The problem is, application terminates each time i close one of the windows. What i need is two separate windows; main application window and the one that gives access to various settings of the application - therefore closing the settings window should not affect the main window. Is there any way to achieve this? Thank you.</p>
  
  <hr>
  
  <p>P.S. My WinMain function is modified like this:</p>
  
  <pre><code>int WINAPI WinMain(HINSTANCE a_hInstance, HINSTANCE a_hPrevInstance, LPTSTR a_lpCmdLine, int a_iCmdShow)
  {
      int iReturnCode;
  
      // Initialise the engine.
      if (!MyEngine.InitInstance(a_hInstance, a_lpCmdLine, a_iCmdShow)) return 0;
  
      // Begin the gameplay process and return when the application due to exit
      iReturnCode = MyEngine.StartEngine();
  
      // Return the correct exit code.
      return iReturnCode;
  }
  </code></pre>
  
  <p>and StaticWndProc looks like this:</p>
  
  <pre><code>LRESULT CALLBACK CMoveEngine::StaticWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
  {
      // If this is a create message, trap the 'this' pointer passed in and store it within the window.
      if (Message == WM_CREATE) SetWindowLong(hWnd, GWL_USERDATA, (LONG)((CREATESTRUCT FAR *)lParam)-&gt;lpCreateParams);
  
      // Obtain the correct destination for this message
      CMoveEngine *Destination = (CMoveEngine*)GetWindowLong(hWnd, GWL_USERDATA);
  
      // If the hWnd has a related class, pass it through
      if (Destination) return Destination-&gt;DisplayWndProc(hWnd, Message, wParam, lParam);
  
      // No destination found, defer to system...
      return DefWindowProc(hWnd, Message, wParam, lParam);
  }
  </code></pre>
  
  <p>Message loop:</p>
  
  <pre><code>int CMoveEngine::StartEngine()
  {
      MSG msg;
  // Start main loop
  while (true) 
  {
      // Did we recieve a message, or are we idling?
      if (PeekMessage(&amp;msg, nullptr, 0, 0, PM_REMOVE)) 
      {
          if (msg.message == WM_QUIT) break;
          TranslateMessage(&amp;msg);
          DispatchMessage (&amp;msg);
      } 
      else 
      {
  
      }
  }
  
  return 0;
  }
  </code></pre>