实例1.3:获得指定点的窗口

获得指定点的窗口使用WindowFromPoint函数  

函数功能:该函数获得包含指定点的窗口的句柄。   

函数原型:HWND WindowFromPoint(POINT Point);   

参数:   Point:指定一个被检测的点的POINT结构。   

返回值S:返回值为包含该点的窗口的句柄。如果包含指定点的窗口不存在,返回值为NULL。如果该点在静态文本控件之上,返回值是在该静态文本控件的下面的窗口的句柄。   

备注:WindowFromPoint函数不获取隐藏或禁止的窗口句柄,即使点在该窗口内。应用程序应该使用ChildWindowFromPoint函数进行无限制查询,这样就可以获得静态文本控件的句柄。

	//获得指定点的窗口
	CWnd* pWnd = WindowFromPoint(point);
	if (pWnd != NULL)
	{
		if (IsChild(pWnd))
		{
			CString strText = _T("");
			pWnd->GetWindowText(strText);
			SetWindowText(strText);
		}
	}
	CDialog::OnMouseMove(nFlags, point);

 另一个函数,IsChild,判断当前窗口是pWnd的子窗口或是CWnd的派生窗口。

Life is like a box of chocolate, you never know what you are going to get.
原文地址:https://www.cnblogs.com/mars9/p/2328033.html