title: Get HWND of each Window?
body: <p>I am developing a python application and I want to get the <code>HWND</code> of each open windows. I need the name of the windows and the <code>HWND</code> to filter the list to manage some specifics windows, moving and resizing them.</p>
  
  <p>I have tried to do it myself looking information around but I did not get the correct piece of code. I tried with this <a href="http://sjohannes.wordpress.com/2012/03/23/win32-python-getting-all-window-titles" rel="noreferrer">code</a> but I only get the title of each windows (that is great), but I need the <code>HWND</code> too.</p>
  
  <pre><code>import ctypes
  import win32gui
  EnumWindows = ctypes.windll.user32.EnumWindows
  EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
  GetWindowText = ctypes.windll.user32.GetWindowTextW
  GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
  IsWindowVisible = ctypes.windll.user32.IsWindowVisible
  
  titles = []
  def foreach_window(hwnd, lParam):
      if IsWindowVisible(hwnd):
          length = GetWindowTextLength(hwnd)
          buff = ctypes.create_unicode_buffer(length + 1)
          GetWindowText(hwnd, buff, length + 1)
          titles.append((hwnd, buff.value))
      return True
  EnumWindows(EnumWindowsProc(foreach_window), 0)
  
  for i in range(len(titles)):
      print(titles)[i]
  
  win32gui.MoveWindow((titles)[5][0], 0, 0, 760, 500, True)
  </code></pre>
  
  <p>There is a error here:</p>
  
  <pre class="lang-none prettyprint-override"><code>win32gui.MoveWindow((titles)[5][0], 0, 0, 760, 500, True)
   TypeError: The object is not a PyHANDLE object
  </code></pre>