前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >FindWindowEx 遍历所有窗口

FindWindowEx 遍历所有窗口

作者头像
全栈程序员站长
发布2022-09-05 08:40:06
1.1K0
发布2022-09-05 08:40:06
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

FindWindowEx 唯一麻烦是第2个参数的指定 .

Explore 下窗口是Z序的 , 实际上就是根据 第一个参数 和 第2个参数 来找 第2个参数后的一个窗口:

HWND child = 0;

child = FindWindowEx ( NULL , child ,NULL,NULL);

这样 , child 就是一个Explore ,

然后 , 通过循环能够找到child 的下一个窗口

代码语言:javascript
复制
//遍历所有子窗口的子窗口 , 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);
}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/138044.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年6月1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档