枚举窗口就像使用Alt-Tab确实 [英] Enumerate windows like alt-tab does

查看:557
本文介绍了枚举窗口就像使用Alt-Tab确实的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了Vista中的ALT标签更换,但我有一些问题,列出所有正在运行的程序。

我使用EnumWindows的目标就是让Windows名单,但这份名单是巨大的。它包含了大约400项目时,我只有10个窗口打开。这似乎是为每一个控制一个HWND和很多其他的东西。

所以,我必须以某种方式过滤此列表,但我不能管理为ALT标签确实做完全是。

这是code我用现在来过滤列表。它的工作原理pretty很好,但我得到了一些不必要的窗户像独立工具窗口在Visual Studio中,我也想念像iTunes和魔兽争霸的窗口。

 私人布尔ShouldWindowBeDisplayed(IntPtr的窗口)
{
    UINT windowStyles = Win32.GetWindowLong(窗口,GWL.GWL_STYLE);    如果(((UINT)WindowStyles.WS_VISIBLE和放大器;!windowStyles)=(UINT)WindowStyles.WS_VISIBLE ||
        ((UINT)WindowExStyles.WS_EX_APPWINDOW&安培; windowStyles)!=(UINT)WindowExStyles.WS_EX_APPWINDOW)
    {
        返回true;
    }
    返回false;
}


解决方案

雷蒙德陈回答了这个前阵子(<一个href=\"http://blogs.msdn.com/oldnewthing/archive/2007/10/08/5351207.aspx\">http://blogs.msdn.com/oldnewthing/archive/2007/10/08/5351207.aspx):


  

它实际上是pretty虽然简单
  几乎没有什么你能猜到
  你自己的。注意:此的细节
  算法是一个实现
  详情。它可以在任何时间改变,所以
  不依赖于它。实际上,它已经
  与Flip和改变的Flip3D;我只是
  说起经典Alt + Tab键
  在此窗口


  
  

对于每一个可见的窗口,走近它
  所有者链,直到找到根
  所有者。然后步行回落可见
  最后一个活动弹出链,直到找到
  一个可见的窗口。如果你回
  你在哪里开始,然后放
  窗口而alt + tab列表。在
  伪code:


  BOOL IsAltTabWindow(HWND HWND)
{
 //开始在根主人
 HWND hwndWalk = GetAncestor(HWND,GA_ROOTOWNER); //看看我们是否是最后一个活动弹出可见
 HWND hwndTry;
 而((hwndTry = GetLastActivePopup(hwndWalk))!= hwndTry){
  如果(IsWindowVisible(hwndTry))打破;
  hwndWalk = hwndTry;
 }
 返回hwndWalk == HWND;
}

按照链接的详细信息和一些拐角条件辰的博客文章。

I'm creating an alt-tab replacement for Vista but I have some problems listing all active programs.

I'm using EnumWindows to get a list of Windows, but this list is huge. It contains about 400 items when I only have 10 windows open. It seems to be a hwnd for every single control and a lot of other stuff.

So I have to filter this list somehow, but I can't manage to do it exactly as alt-tab does.

This is the code I use to filter the list right now. It works pretty well, but I get some unwanted windows like detached tool-windows in Visual Studio and I also miss windows like iTunes and Warcraft3.

private bool ShouldWindowBeDisplayed(IntPtr window)
{
    uint windowStyles = Win32.GetWindowLong(window, GWL.GWL_STYLE);

    if (((uint)WindowStyles.WS_VISIBLE & windowStyles) != (uint)WindowStyles.WS_VISIBLE ||
        ((uint)WindowExStyles.WS_EX_APPWINDOW & windowStyles) != (uint)WindowExStyles.WS_EX_APPWINDOW)
    {
        return true;
    }
    return false;
}

解决方案

Raymond Chen answered this a while back (http://blogs.msdn.com/oldnewthing/archive/2007/10/08/5351207.aspx):

It's actually pretty simple although hardly anything you'd be able to guess on your own. Note: The details of this algorithm are an implementation detail. It can change at any time, so don't rely on it. In fact, it already changed with Flip and Flip3D; I'm just talking about the Classic Alt+Tab window here.

For each visible window, walk up its owner chain until you find the root owner. Then walk back down the visible last active popup chain until you find a visible window. If you're back to where you're started, then put the window in the Alt+Tab list. In pseudo-code:

BOOL IsAltTabWindow(HWND hwnd)
{
 // Start at the root owner
 HWND hwndWalk = GetAncestor(hwnd, GA_ROOTOWNER);

 // See if we are the last active visible popup
 HWND hwndTry;
 while ((hwndTry = GetLastActivePopup(hwndWalk)) != hwndTry) {
  if (IsWindowVisible(hwndTry)) break;
  hwndWalk = hwndTry;
 }
 return hwndWalk == hwnd;
}

Follow the link to Chen's blog entry for more details and some corner conditions.

这篇关于枚举窗口就像使用Alt-Tab确实的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆