枚举所有子窗口,包括POPUP窗口

枚举所有子窗口,包括POPUP窗口


以前在实现这个功能时,在网上找了好久,都未达到目标,
在查找POPup窗口,未找到时,会无限循环到,堆栈溢出的问题,实在在网上没有找到处理办法,
没办法的情况下,使用 std::set &DoneSet 来记录检查过的窗口.

DoneSet 用来记录已查找过的窗口,
///如果不检查,在查找POPup窗口,未找到时,会无限循环到,堆栈溢出。
static HWND MyFindWndSub(HWND hparent, CString &tilte,std::set &DoneSet)
{
if (DoneSet.find(hparent)!=DoneSet.end())
{
return NULL;
}
DoneSet.insert(hparent);

HWND pwnd;
pwnd = ::GetWindow(hparent, GW_CHILD);
if (pwnd)
{
	HWND cw = pwnd;
	do
	{
		int id = ::GetDlgCtrlID(cw);
		if (id >= 0X300 && id < 0x400)
		{
			TCHAR ts[1024];
			::GetWindowText(cw,ts,1024);			 
			if (0 == _tcsicmp(tilte,ts))
			{
				return cw;
			}
		}
		查找子窗口
		HWND rw = MyFindWndSub(cw, tilte,DoneSet);
		if (rw)
		{
			return rw;
		}

		cw =GetWindow(cw,GW_HWNDNEXT);
	}
	while(cw);
}

pwnd =::GetWindow( hparent, GW_ENABLEDPOPUP);

while(pwnd )
{ 
	HWND cw = pwnd;

	int id = ::GetDlgCtrlID(cw);
	if (id >= 0X300 && id < 0x400)
	{
		TCHAR ts[1024];
		 
		::GetWindowText(cw,ts,1024);

		if (0 == _tcsicmp(tilte,ts))
		{
			return cw;
		}
	}
	HWND fw = MyFindWndSub(pwnd, tilte,DoneSet);
	if (fw)
	{
		return fw;
	}

	pwnd = ::GetWindow(pwnd, GW_HWNDNEXT);
}
return NULL;

}

HWND MyFindWnd(HWND hparent, CString &tilte)
{
std::set DoneSet;
return MyFindWndSub(hparent,tilte,DoneSet);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值