遍历窗口中的所有控件

版权声明:本文为博主原创文章,未经博主允许不可以转载。 https://blog.csdn.net/aasmfox/article/details/80521202

要操作对话框中的子控件,可以根据当前鼠标点击的point 进行判断.

PtInRect可以判断点击是否在目标区域内,然后返回对应的窗口句柄.

以下都是测试代码,用于作个笔记。

1.遍历控件对象

	HWND hWindow   =m_hWnd; 
	CString strText ; 
	int nIndex = 0 ; 
	hWindow =::GetWindow(hWindow,GW_CHILD|GW_HWNDFIRST);; 
	if(hWindow)
	{
		Control.Add( hWindow); 
	}
	else
	{
		return -1;
	}

	while (hWindow)
	{
		hWindow =  ::GetNextWindow(hWindow,  GW_HWNDNEXT  );
		Control.Add( hWindow); 
	}
 
	return 0;

2.判断当前鼠标点击了哪个控件

HWND hWindow = 0 ; 

	int iSize = Control.GetSize() -1; 

	for (int i=iSize ;i>0;i--)
	{
		CWnd*pWnd = FromHandle(Control[i]) ; 
		if(::IsWindow(Control[i]) ==FALSE)
		{
			continue;  
		}

		CRect r ; 
		pWnd->GetWindowRect(r);
		ScreenToClient(&r);

		if(PtInRect(&r,pt))
		{
			return Control[i];
		}
	}
 


猜你喜欢

转载自blog.csdn.net/aasmfox/article/details/80521202
今日推荐