问题描述
微软WinAPI的文件似乎表明,user32.dll中含有一种叫函数这理应使人们通过反复调用这个函数来枚举在其Z序打开的窗口。
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.
通常给我一点的DllImport
语句中使用WinAPI的函数从C#。然而,对于 GetNextWindow()
它没有一个条目。于是,我就建立我自己的:
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);
不幸的是,试图调用这个的时候,我得到一个 EntryPointNotFoundException
说:
Unable to find an entry point named 'GetNextWindow' in DLL 'user32.dll'.
这似乎只适用于 GetNextWindow()
;这是对的PInvoke列出的其他功能都正常。我可以叫 GetTopWindow()
和 GetWindowText函数()
没有抛出异常。
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.
当然,如果你能提出一个完全不同的方式来枚举窗口在其当前Z序,我很高兴听到这一点。
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.
推荐答案
GetNextWindow()其实就是 GetWindow(),而不是实际的API方法。它是与Win16的API向后兼容性。
GetNextWindow() is actually a macro for GetWindow(), rather than an actual API method. It's for backward compatibility with the Win16 API.
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
enum GetWindow_Cmd : uint {
GW_HWNDFIRST = 0,
GW_HWNDLAST = 1,
GW_HWNDNEXT = 2,
GW_HWNDPREV = 3,
GW_OWNER = 4,
GW_CHILD = 5,
GW_ENABLEDPOPUP = 6
}
(从)
这篇关于我如何在C#中使用GetNextWindow()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!