опубликован 24-11-2001 11:41 MSK
WindowFromPoint
The WindowFromPoint function retrieves a handle to the window that contains the specified point. HWND WindowFromPoint(
POINT Point // point
);
Parameters
Point
[in] Specifies a POINT structure that defines the point to be checked.
Return Values
The return value is a handle to the window that contains the point. If no window exists at the given point, the return value is NULL. If the point is over a static text control, the return value is a handle to the window under the static text control.
Remarks
The WindowFromPoint function does not retrieve a handle to a hidden or disabled window, even if the point is within the window. An application should use the ChildWindowFromPoint function for a nonrestrictive search.
Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.
или
HWND ChildWindowFromPoint(
HWND hWndParent, // handle to parent window
POINT Point // structure with point coordinates
);
или
HWND RealChildWindowFromPoint(
HWND hwndParent, // handle to window
POINT ptParentClientCoords // client coordinates
);
.
.
.
а лучше
HWND SmallestWindowFromPoint(const POINT point)
{
RECT rect, rectSearch;
HWND pWnd, hWnd, hSearchWnd;
hWnd = WindowFromPoint(point);
if(hWnd != NULL)
{
GetWindowRect(hWnd, &rect);
pWnd = GetParent(hWnd);
if(pWnd != NULL)
{
hSearchWnd = hWnd;
do
{
hSearchWnd = GetWindow(hSearchWnd, GW_HWNDNEXT);
GetWindowRect(hSearchWnd, &rectSearch);
if(PtInRect(&rectSearch, point) && ::GetParent(hSearchWnd) == pWnd && ::IsWindowVisible(hSearchWnd))
{
if(((rectSearch.right - rectSearch.left) * (rectSearch.bottom - rectSearch.top)) < ((rect.right - rect.left) * (rect.bottom - rect.top)))
{
hWnd = hSearchWnd;
GetWindowRect(hWnd, &rect);
}
}
}
while(hSearchWnd != NULL);
}
}
return hWnd;
}