简体   繁体   English

C#-获取活动窗口正下方的窗口句柄?

[英]C# - get handle of window right beneath the active window?

Is it possible somehow to get the handle of the window below the current active window retrieved by GetForegroundWindow , z-order wise? 是否有可能以某种方式使窗口的句柄位于GetForegroundWindow检索的当前活动窗口下方(z阶明智)? In other words, the window that is beneath the current one, no matter its size and position. 换句话说,当前窗口下方的窗口,无论其大小和位置如何。

You may try this pinvoke calls: 您可以尝试以下拨打电话:

[DllImport("User32")] extern IntPtr GetTopWindow(IntPtr hWnd); 
[DllImport("User32")] extern IntPtr GetNextWindow(IntPtr hWnd, uint wCmd); 

and use this as parameter 并将其用作参数

uint GW_HWNDNEXT = 2; 

So first get the top window (or yours). 因此,首先获取(或您的)顶部窗口。 After that call GetNextWindow and for the result handle again and again,... so you will get all windows 在那之后,调用GetNextWindow并一次又一次地对结果句柄进行操作,这样您将获得所有窗口

You can get the next or previous window (z-order wise) with the GetNextWindow function. 您可以使用GetNextWindow函数获取下一个或上一个窗口(z阶明智)。

EDIT: I just read on pinvoke.net that GetNextWindow is a macro of GetWindow . 编辑:我刚刚在pinvoke.net上阅读到, GetNextWindowGetWindow的宏。 So you might as well call GetWindow directly: 因此,您最好直接调用GetWindow

Code from pinvoke.net : 来自pinvoke.net的代码:

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd 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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM