title: Flickering UI problems - what causes the DWM in windows 7 to decide to refresh immediately upon calling SetWindowPos?
body: <p>I have a custom tabbed style control, and internally it works by showing or hiding the relevant page when you click on a tab.</p>
  
  <p>The basic order of things that happen when you click a tab is</p>
  
  <ol>
  <li>Bring relevant page to front</li>
  <li>Show relevant page (by calling SetWindowPos with the appropriate flags)</li>
  <li>Hide the old page that we just covered up</li>
  <li>Repaint the window</li>
  </ol>
  
  <p>Some of my tabs are rendered with DirectX. Under Windows XP everything works fine and there's no flicker when you switch between tabs. Under Windows 7 though (or Vista), the call to SetWindowPos in step 2 redraws the window, and there's a flash of uninitialized pixels before step 4, usually whatever was on the desktop before my app started running.</p>
  
  <p>This only happens with the DirectX pages, but I'm not sure what it is about DirectX that would cause this, if anything - there are other differences between the pages as well, that was just the obvious pattern. I'm not sure if this is a real clue or a red herring.</p>
  
  <p>The GDI pages don't repaint until step 4. I stepped through the code and checked - it's not just that the DWM uses a correctly cached bitmap in step 2 - it really doesn't repaint at all until step 4.</p>
  
  <p>That's the background info, but at the moment I'm not sure how to tackle this specific problem, so my question is more general:</p>
  
  <p>What are all the things that can affect SetWindowPos's decision to repaint or not?</p>