title: Trouble capturing window with winAPI BitBlt for some applications only
body: <p>I've put together a simple python script that is supposed to take a screenshot of a window whose name contains a specific string. The code I use is the following,</p>
  
  <pre>
  <code>
  import win32gui, win32ui, win32con
  import PIL.Image
  
  def getWindowHandle(name):        
      windowList = []
      win32gui.EnumWindows(lambda hwnd, wndList:
                               wndList.append((win32gui.GetWindowText(hwnd), hwnd)),
                           windowList)
  
      for pair in windowList:
          if name in pair[0]:
              return pair[1]
  
      return None
  
  
  class Window():
      def __init__(self, hwnd = None):
          if not hwnd: return
  
          l, t, r, b   = win32gui.GetClientRect(hwnd)
          sl, st, _, _ = win32gui.GetWindowRect(hwnd)
          cl, ct       = win32gui.ClientToScreen(hwnd, (l, t))
  
          self.size     = (r - l, b - t)
          self.position = (cl - sl, ct - st)
  
          hDC   = win32gui.GetWindowDC(hwnd)
          self.windowDC  = win32ui.CreateDCFromHandle(hDC)
          self.newDC = self.windowDC.CreateCompatibleDC()
  
          #win32gui.ReleaseDC(hwnd, hDC)
  
          self.bitmap = win32ui.CreateBitmap()
          self.bitmap.CreateCompatibleBitmap(self.windowDC, self.size[0], self.size[1])
          self.newDC.SelectObject(self.bitmap)
  
      def __del__(self):
          self.newDC.DeleteDC()
          self.windowDC.DeleteDC()
          del self.bitmap
  
      def screenshot(self, location = 'C:\\Users\\Grieverheart\\Desktop\\'):
          self.newDC.BitBlt((0, 0), self.size, self.windowDC, self.position, win32con.SRCCOPY)
          self.bitmap.Paint(self.newDC)
  
          bmpinfo = self.bitmap.GetInfo()
          bmpstr  = self.bitmap.GetBitmapBits(True)
          im = PIL.Image.frombuffer('RGB', self.size, bmpstr, 'raw', 'BGRX', 0, 1)
          try:
              im.save(location + 'test.png', 'PNG')
          except IOError:
              return
  
  
  def main():
      handle = getWindowHandle("Blender")
      if not handle: return
  
      window = Window(handle)
      window.screenshot()
  
  if __name__ == "__main__":
      main()
  </code>
  </pre>
  
  <p>The script gives me a black screenshot for some applications, such as Blender or DOSBox.</p>
  
  <p>Does anyone know what causes this issue for only some applications and how I could fix it?</p>
  
  <p><strong>EDIT</strong>: It seems my problem might be related to <a href="https://stackoverflow.com/questions/2899655/bitblt-ignores-captureblt-and-seems-to-always-capture-a-cached-copy-of-the-targe" title="this">this</a> post, although I am not sure what I'd have to do to fix my issue. I'd also like to add that I have also tried the adding CAPTUREBLT flag without any differences.</p>