title: My window doesn't paint properly when it's not running in the debugger
body: <p>I have a Win32 program (desktop app) that works fine when debugging (started by <kbd>F5</kbd>), but it doesn't paint the window, nor its title when run without debugging (<kbd>Ctrl + F5</kbd>). How is that possible ? I'm using VS 2010.</p>
  
  <p>Edit: in Release build the code works fine with without debugging, but it doesn't in the debugger, which is exactly the opposite of what happens in Debug build.</p>
  
  <p>New Edit:</p>
  
  <p>After many hours working on this, I found out that the problem somehow is related to the initialization of a static std::auto_ptr object with its reset() member function.</p>
  
  <p>Remember what I said above, that the window title doesn't show on the app window, and this title is set up with SetWindowText(hwnd, L"Any Title") at the end of the WM_CREATE message processing. I then started moving backwards this function call, within WM_CREATE, to see exactly where it failed to exhibit the window's title. And that occurs after the first initialization of a static std::auto_ptr object like the pseudo-code below :</p>
  
  <pre><code>class A{};
  
  LRESULT CALLBACK WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam)
  {
      static std::auto_ptr&lt;A&gt; a;
      switch ( message )
      {
          case WM_CREATE:
          {
              ...
              a.reset(new A);
              SetWindowText(hwnd, L"Any Title");
              ...
          }
          break;
  
          case WM_PAINT:
  
          ...
  
          break;
  
          case WM_DESTROY:
  
          PostQuitMessage(0);
          break;
  
          default:
  
          return DefWindowProc(hwnd, message, wParam, lParam);
      }
      return 0;
  }
  </code></pre>
  
  <p>That means, if I call SetWindowText() before the initialization of the variable <code>a</code>, the window title is shown correctly, although it doesn't show any text on its client area, when the window gets painted. I know the window is being painted, for I inserted a <code>MessageBeep(-1)</code> in <code>WM_PAINT</code>, and I can hear the sound.</p>
  
  <p>It's also interesting to mention that everything that is printed in WM_PAINT comes from <code>class A</code> objects allocated on the heap, whose addresses are encapsulated in <code>std::auto_ptr</code> objects.</p>
  
  <p>Of course, all this is happening when executing the code with <kbd>Ctrl + F5</kbd>. When the program is launched with <kbd>F5</kbd> everything works fine.</p>
  
  <p>New Edit :</p>
  
  <p>I changed the <code>std::auto_ptr</code> variables to <code>unique_ptr</code> to no avail. The problem continues.     </p>