void CTestDlg::OnTest()
{
POINT pt;
GetCursorPos(&pt);//获取坐标
HWND hHandle = ::WindowFromPoint(pt);
if (hHandle == m_hWnd)
{
MessageBox("OK");
}
}原型:
HWND ChildWindowFromPoint(
HWND hWndParent, //handle to parent window
POINT Point //the coordinates(relative to hWndParent) of the point to be checked
);
功能:返回包含这个点的窗口句柄,即使窗口隐藏或者处于无效状态。(需要指定某个容器窗体,返回该容器窗体中包含点的窗口句柄)
返回值:如果点不在父窗口内,则返回NULL,如果点在父窗口内,但不在任何子窗口上,则返回父窗口的句柄。
另外,特别要注意的是:参数Point不是屏幕坐标,而是相对于容器窗口的坐标。
例如:
当鼠标放在m_button上时,返回OK。
void CTestDlg::OnOK()
{
POINT pt;
GetCursorPos(&pt);
BOOL bOK = ::ScreenToClient(m_hWnd, &pt);
if (!bOK)
{
return;
}
HWND hHandle = ::ChildWindowFromPoint(m_hWnd, pt);
if (hHandle == m_button.m_hWnd)
{
MessageBox("OK");
}
}
WindowFromPoint()与ChildWindowFromPoint()的区别
原文:http://blog.csdn.net/jiangqin115/article/details/44916473