您的位置:首页 > 其它

寻找包含一个点的最小窗口:WindowFromPoint

2016-12-22 10:51 405 查看
1
搜寻包含一个点的最小窗口
/************************************************************************
// SmallestWindowFromPoint
// Find the smallest window still containing the point
// WindowFromPoint returns the first window in the Z-order
// if the password control is sorounded by a Group Box or some other control,
// WindowFromPoint returns the handle to the sorounding control instead
// to the password control.
************************************************************************/
HWND SmallestWindowFromPoint(POINT point)
{
RECT rect, rcTemp;
HWND hParent, hWnd, hTemp;

hWnd = ::WindowFromPoint(point);
if( hWnd != NULL ) {
::GetWindowRect(hWnd, &rect);
hParent = ::GetParent(hWnd);

// Has window a parent ?
if(hParent != NULL) {
// Search down the Z-Order
hTemp = hWnd;
do {
hTemp = ::GetWindow(hTemp, GW_HWNDNEXT);

// Search window contains the point, has the same parent, and is visible?
::GetWindowRect(hTemp, &rcTemp);
if(::PtInRect(&rcTemp, point) && ::GetParent(hTemp) == hParent && ::IsWindowVisible(hTemp)){
// Is it smaller?
if(((rcTemp.right - rcTemp.left) * (rcTemp.bottom - rcTemp.top)) < ((rect.right - rect.left) * (rect.bottom - rect.top))) {
// Found new smaller window!
hWnd = hTemp;
::GetWindowRect(hWnd, &rect);
}
}
} while(hTemp != NULL);
}
}
return hWnd;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐