The Microsoft WinAPI documentation appears to suggest that user32.dll contains a function called GetNextWindow()
which supposedly allows one to enumerate open windows in their Z order by calling this function repeatedly.
Pinvoke usually gives me the necessary DllImport
statement to use WinAPI functions from C#. However, for GetNextWindow()
it doesn't have an entry. So I tried to construct my own:
[DllImport("user32.dll")]
static extern IntPtr GetNextWindow(IntPtr hWnd, uint wCmd);
Unfortunately, when trying to call this, I get an EntryPointNotFoundException
saying:
Unable to find an entry point named 'GetNextWindow' in DLL 'user32.dll'.
This seems to apply only to GetNextWindow()
; other functions that are listed on Pinvoke are fine. I can call GetTopWindow()
and GetWindowText()
without throwing an exception.
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.