1. Windowfrompoint ()
Function prototype: HWND windowfrompoint (Point point);
function function: The function obtains the handle of the window containing the specified point, which refers to the screen coordinates
Parameters:
Point: Specifies the DOT structure of the detected points.
return value:
The return value is a handle to the window that contains the point. Returns null if there is no window that contains this point. Returns null if the window is invalid or hidden.
By testing, it is found that the handle to the parent window is returned when a partial control handle is obtained. Includes static Text, GroupBox, and so on.
For example:
void Ctestdlg::ontest () {Point pt; GetCursorPos (&PT);//Get coordinates hWnd Hhandle =:: Windowfrompoint (PT); if (Hhandle = = m_hwnd) {MessageBox ("OK");}}
2. Childwindowfrompoint ()
Prototype:
HWND Childwindowfrompoint (
HWND hWndParent,//handle to parent window
Point Point//the coordinates (relative to hwndparent) of the point to be checked
);
Function: Returns the window handle that contains the point, even if the window is hidden or in an invalid state. (You need to specify a container form that returns a window handle that contains a point in the container form)
Return value: Returns NULL if the point is not within the parent window, and returns a handle to the parent window if the point is inside the parent window but not on any child windows.
Also, it is important to note that the parameter point is not a screen coordinate, but rather the coordinates of the container window.
For example:
Returns OK when the mouse is over the M_button. 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");}}
The difference between windowfrompoint () and Childwindowfrompoint ()