【问题标题】:C# - get handle of window right beneath the active window?C# - 获取活动窗口正下方的窗口句柄?
【发布时间】:2012-08-10 14:31:56
【问题描述】:

是否有可能以某种方式获取GetForegroundWindow 检索到的当前活动窗口下方的窗口句柄,z 顺序明智?换言之,当前窗口下方的窗口,无论其大小和位置如何。

【问题讨论】:

    标签: c# pinvoke


    【解决方案1】:

    你可以试试这个 pinvoke 电话:

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

    并将其用作参数

    uint GW_HWNDNEXT = 2; 
    

    所以首先获取顶部窗口(或您的)。之后调用 GetNextWindow 并一次又一次地处理结果,......所以你会得到所有的窗口

    【讨论】:

    • 你实际上不能调用GetNextWindow,因为它是GetWindow的子函数(应该被调用),有点误导。 :)
    【解决方案2】:

    您可以使用GetNextWindow 函数获取下一个或上一个窗口(z 顺序)。

    编辑:我刚刚在 pinvoke.net 上看到 GetNextWindowGetWindow 的宏。所以你不妨直接拨打GetWindow

    来自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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-26
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      相关资源
      最近更新 更多