HWND GetMouseWindow(CPoint& point) { // Find the smallest "window" still containing the point // Doing this prevents us from stopping at the first window containing the point RECT rect, rectSearch; HWND hParentWnd, hWnd, hSearchWnd; hWnd = ::WindowFromPoint(point); if(hWnd != NULL) { // Get the size and parent for compare later ::GetWindowRect(hWnd, &rect); hParentWnd = ::GetParent(hWnd); // We only search further if the window has a parent if(hParentWnd != NULL) { // Search from the window down in the Z-Order hSearchWnd = hWnd; do{ hSearchWnd = ::GetWindow(hSearchWnd, GW_HWNDNEXT); // Does the search window also contain the point, have the same parent, and is visible? ::GetWindowRect(hSearchWnd, &rectSearch); if(::PtInRect(&rectSearch, point) && ::GetParent(hSearchWnd) == hParentWnd && ::IsWindowVisible(hSearchWnd)) { // It does, but is it smaller? if(((rectSearch.right - rectSearch.left) * (rectSearch.bottom - rectSearch.top)) < ((rect.right - rect.left) * (rect.bottom - rect.top))) { // Found new smaller window, update compare window hWnd = hSearchWnd; ::GetWindowRect(hWnd, &rect); } } }while(hSearchWnd != NULL); } } return hWnd; }
{
// Find the smallest "window" still containing the point
// Doing this prevents us from stopping at the first window containing the point
RECT rect, rectSearch;
HWND hParentWnd, hWnd, hSearchWnd; hWnd = ::WindowFromPoint(point);
if(hWnd != NULL)
{
// Get the size and parent for compare later
::GetWindowRect(hWnd, &rect);
hParentWnd = ::GetParent(hWnd); // We only search further if the window has a parent
if(hParentWnd != NULL)
{
// Search from the window down in the Z-Order
hSearchWnd = hWnd;
do{
hSearchWnd = ::GetWindow(hSearchWnd, GW_HWNDNEXT); // Does the search window also contain the point, have the same parent, and is visible?
::GetWindowRect(hSearchWnd, &rectSearch);
if(::PtInRect(&rectSearch, point) && ::GetParent(hSearchWnd) == hParentWnd && ::IsWindowVisible(hSearchWnd))
{
// It does, but is it smaller?
if(((rectSearch.right - rectSearch.left) * (rectSearch.bottom - rectSearch.top)) < ((rect.right - rect.left) * (rect.bottom - rect.top)))
{
// Found new smaller window, update compare window
hWnd = hSearchWnd;
::GetWindowRect(hWnd, &rect);
}
}
}while(hSearchWnd != NULL);
}
} return hWnd;
}