为什么EnumWindows返回比我预期的更多的窗口? [英] Why does EnumWindows return more windows than I expected?

查看:207
本文介绍了为什么EnumWindows返回比我预期的更多的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VC ++中,我使用EnumWindows(...),GetWindow(...)和GetWindowLong()来获取窗口列表,并检查窗口是否是顶部窗口(没有其他窗口作为所有者)窗口是否可见(WS_VISIBLE)。然而,虽然我的桌面只显示5个窗口,这个EnumWindows给了我50个窗口,多么有趣!任何Windows怪胎在这里请帮我澄清...

解决方案

只列出窗口任务栏-Tab框)由Raymond在本文中的MSDN博客上描述:

http://blogs.msdn.com/b/oldnewthing/archive/2007/10/08/5351207.aspx



这个是检查窗口是否显示在alt-tab中的超级函数:

  BOOL IsAltTabWindow(HWND hwnd)
{
TITLEBARINFO ti;
HWND hwndTry,hwndWalk = NULL;

if(!IsWindowVisible(hwnd))
return FALSE;

hwndTry = GetAncestor(hwnd,GA_ROOTOWNER);
while(hwndTry!= hwndWalk)
{
hwndWalk = hwndTry;
hwndTry = GetLastActivePopup(hwndWalk);
if(IsWindowVisible(hwndTry))
break;
}
if(hwndWalk!= hwnd)
return FALSE;

//以下删除一些任务托盘程序和程序管理器
ti.cbSize = sizeof(ti);
GetTitleBarInfo(hwnd,& ti);
if(ti.rgstate [0]& STATE_SYSTEM_INVISIBLE)
return FALSE;

//工具窗口也不应显示,这些不会出现在
//任务栏中。
if(GetWindowLong(hwnd,GWL_EXSTYLE)& WS_EX_TOOLWINDOW)
return FALSE;

return TRUE;
}

归功于此处的源代码:

http://www.dfcd.net/projects/switcher/switcher.c


In VC++, I use EnumWindows(...), GetWindow(...), and GetWindowLong(), to get the list of windows and check whether the window is top window (no other window as owner), and whether the window is visible (WS_VISIBLE). However, although my desktop is showing only 5 windows, this EnumWindows is giving me 50 windows, how funny! Any Windows geek here please help me clarify...

解决方案

The way to list out only windows in taskbar (or similarly in Alt-Tab box) is described by Raymond in this article on MSDN blog:
http://blogs.msdn.com/b/oldnewthing/archive/2007/10/08/5351207.aspx

And this is the super function to check whether a window is shown in alt-tab:

BOOL IsAltTabWindow(HWND hwnd)
{
    TITLEBARINFO ti;
    HWND hwndTry, hwndWalk = NULL;

    if(!IsWindowVisible(hwnd))
        return FALSE;

    hwndTry = GetAncestor(hwnd, GA_ROOTOWNER);
    while(hwndTry != hwndWalk) 
    {
        hwndWalk = hwndTry;
        hwndTry = GetLastActivePopup(hwndWalk);
        if(IsWindowVisible(hwndTry)) 
            break;
    }
    if(hwndWalk != hwnd)
        return FALSE;

    // the following removes some task tray programs and "Program Manager"
    ti.cbSize = sizeof(ti);
    GetTitleBarInfo(hwnd, &ti);
    if(ti.rgstate[0] & STATE_SYSTEM_INVISIBLE)
        return FALSE;

    // Tool windows should not be displayed either, these do not appear in the
    // task bar.
    if(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)
        return FALSE;

    return TRUE;
}

Credited to the source code here:
http://www.dfcd.net/projects/switcher/switcher.c

这篇关于为什么EnumWindows返回比我预期的更多的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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