FindWindowEx 遍历所有窗口

版权声明: https://blog.csdn.net/dashoumeixi/article/details/83754279

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);
}

猜你喜欢

转载自blog.csdn.net/dashoumeixi/article/details/83754279