为什么EnumWindows返回比我预期的更多的窗口? [英] Why does EnumWindows return more windows than I expected?
问题描述
只列出窗口任务栏-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屋!