惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
The Exploit Database - CXSecurity.com
B
Blog RSS Feed
G
GRAHAM CLULEY
Microsoft Azure Blog
Microsoft Azure Blog
Know Your Adversary
Know Your Adversary
N
Netflix TechBlog - Medium
A
Arctic Wolf
W
WeLiveSecurity
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
The Blog of Author Tim Ferriss
AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta
T
Threatpost
博客园 - 叶小钗
G
Google Developers Blog
U
Unit 42
Latest news
Latest news
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
Hacker News: Ask HN
Hacker News: Ask HN
MongoDB | Blog
MongoDB | Blog
H
Hacker News: Front Page
F
Fortinet All Blogs
T
Tailwind CSS Blog
The Register - Security
The Register - Security
Apple Machine Learning Research
Apple Machine Learning Research
C
CXSECURITY Database RSS Feed - CXSecurity.com
H
Heimdal Security Blog
A
About on SuperTechFans
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CERT Recently Published Vulnerability Notes
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News and Events Feed by Topic
Application and Cybersecurity Blog
Application and Cybersecurity Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Schneier on Security
Schneier on Security
Y
Y Combinator Blog
V
Visual Studio Blog
GbyAI
GbyAI
Forbes - Security
Forbes - Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
N
News | PayPal Newsroom
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs

博客园 - 数字冰块

VS2005 中文版的翻译 - 数字冰块 - 博客园 Requirements Analysis with 'pseud-Formal' Method 微软亚洲研究院夏令营记 软件学院学习体验之三 关于权限模型 .netcpu?!见过了吗? 着手准备开源桌面 Blog 软件 一定要记住:Page.IsPostBack 不能忘。。。 软件学院学习体验之二 VS.NET 服务器资源管理器、Smartphone 模拟器中的程序调试、虚拟网卡、Smartphone 设备上的程序调试及其他。 软件学院学习体验之一 啥叫“Functional Programming ”??? 一个奇怪的问题 什么是高质量的代码? C#中的析构函数 关于.NET异步调用的初步总结 毕业了。。。 两年以后重读了一篇文章,写了点东西。 微软的宣传图片
关于使用 EnumWindows 枚举应用程序窗口的技巧
数字冰块 · 2006-01-26 · via 博客园 - 数字冰块

最近在写一个 Alt-Tab 替换程序,需要枚举可切换的应用程序窗口。枚举窗口一般使用的是 EnumWindows 函数

BOOL EnumWindows(
       WNDENUMPROC lpEnumFunc,
    LPARAM lParam
);

但是光是使用这个函数并不能得到我们最需要的窗口,它枚举出的窗口有点“多”,包含隐藏的,包含带有子窗体属性的,包含只出现在任务栏通知区域的。。。等等。因而需要有一些过滤条件。我在 Google 上找了很久都没有一个满意的答案,只能自己用 Spy++ 观察一些窗口做了个过滤规则,经过过滤的就是“可显示、可激活、可切换”的窗口。过滤规则请见代码注释。

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
    
//窗口是否可视
    if (!IsWindowVisible(hwnd))
        
return TRUE;

    
//窗口是否可激活
    if (!IsWindowEnabled(hwnd))
        
return TRUE;

    
//窗口是否 WS_POPUP 与 WS_CAPTION 共存
        //一些可切换的窗体同时具有 WS_POPUP 与 WS_CAPTION,因而有 WS_POPUP 却无 WS_CAPTION 的应被过滤
    
//据 Spy++ 观察,符合如 OneNote TrayIcon 等程序可通过此方式过滤
    LONG gwl_style = GetWindowLong(hwnd,GWL_STYLE);
    
if ((gwl_style & WS_POPUP) && !(gwl_style & WS_CAPTION))
        
return TRUE;

    
//窗口是否具有父窗口?
    HWND hParent = (HWND)GetWindowLong(hwnd,GWL_HWNDPARENT);
    
//父窗口是否可激活?
    
//据 Spy++ 观察,如“运行”对话框等被应列入列表的程序有一个隐藏的,具有 WS_DISABLED 的父窗口
    if (IsWindowEnabled(hParent))
        
return TRUE;
    
//父窗口是否可视?
    if (IsWindowVisible(hParent))
        
return TRUE;

    
//一个非常奇怪的问题在于,任务栏 Shell_TrayWnd 符合上述过滤条件但是无法被过滤。
        //因而在这里单独列出。
    TCHAR szClassName[MAX_LOADSTRING];
    GetClassName(hwnd,szClassName,MAX_LOADSTRING);
    
if (!wcscmp(szClassName,L"Shell_TrayWnd"))
        
return TRUE;
..........
..........略