FindWindowEx 唯一麻烦是第2个参数的指定 .
Explore 下窗口是Z序的 , 实际上就是根据 第一个参数 和 第2个参数 来找 第2个参数后的一个窗口:
HWND child = 0;
child = FindWindowEx ( NULL , child ,NULL,NULL);
这样 , child 就是一个Explore ,
然后 , 通过循环能够找到child 的下一个窗口
//遍历所有子窗口的子窗口 , Z序遍历
void print_window2(HWND parent , int level)
{
HWND child = NULL;
TCHAR buf[MAX_PATH];
DWORD pid = 0, tid = 0;
do{
child = FindWindowEx(parent, child, NULL, NULL);
int ret = GetWindowText(child, buf, MAX_PATH);
buf[ret] = 0;
tid = GetWindowThreadProcessId(child, &pid);
for (int i = 0; i < level; ++i)
_tprintf(L"\t");
_tprintf(L"%s , pid:%d, tid:%d\n", buf, pid, tid);
if (child)
print_window2(child , level + 1);
} while (child);
}
//遍历所有 explore 下的窗口 , Z序遍历
void print_window()
{
HWND child = NULL;
TCHAR buf[MAX_PATH];
DWORD pid = 0, tid = 0;
do{
//查找 Explore 下的一个窗口,如果能找到则根据 Explore 下的child 继续找
child = FindWindowEx(NULL, child, NULL, NULL);
int ret = GetWindowText(child, buf, MAX_PATH);
buf[ret] = 0;
tid = GetWindowThreadProcessId(child, &pid);
_tprintf(L"%s , pid:%d, tid:%d\n", buf, pid, tid);
//遍历子窗口们
if (child)
print_window2(child, 1);
} while (child);
}
本文介绍使用FindWindowEx函数结合Z序遍历窗口的方法。通过示例代码展示了如何遍历所有子窗口及其子窗口,实现对Explore窗口及其后续窗口的遍历。文章深入解析了FindWindowEx函数的第二个参数作用,以及如何通过循环找到指定窗口后的所有窗口。
1408

被折叠的 条评论
为什么被折叠?



