title: How can I use GetNextWindow() in C#?
body: <p>The Microsoft WinAPI documentation appears to suggest that user32.dll contains a function called <a href="http://msdn.microsoft.com/en-us/library/ms633509(VS.85).aspx" rel="noreferrer"><code>GetNextWindow()</code></a> which supposedly allows one to enumerate open windows in their Z order by calling this function repeatedly.</p>
  
  <p><a href="http://www.pinvoke.net/" rel="noreferrer">Pinvoke</a> usually gives me the necessary <code>DllImport</code> statement to use WinAPI functions from C#. However, for <code>GetNextWindow()</code> it doesn't have an entry. So I tried to construct my own:</p>
  
  <pre><code>[DllImport("user32.dll")]
  static extern IntPtr GetNextWindow(IntPtr hWnd, uint wCmd);
  </code></pre>
  
  <p>Unfortunately, when trying to call this, I get an <code>EntryPointNotFoundException</code> saying:</p>
  
  <pre><code>Unable to find an entry point named 'GetNextWindow' in DLL 'user32.dll'.
  </code></pre>
  
  <p>This seems to apply only to <code>GetNextWindow()</code>; other functions that are listed on Pinvoke are fine. I can call <code>GetTopWindow()</code> and <code>GetWindowText()</code> without throwing an exception.</p>
  
  <p>Of course, if you can suggest a completely different way to enumerate windows in their current Z order, I'm happy to hear that too.</p>