So, I have a plugin to an MFC program. I’m using a mouse event hook (from SetWindowsHookEx) to capture clicks. The host application can have any number of (possibly overlapping) child windows open, but I only want to intercept clicks in a particular child window.
Is there a way to figure out in the hook proc which of the child windows would process the click? I guess it’s something like enumerate all child windows, looking at Z-order, but I’m very unfamiliar with the MFC/Win32 libraries, and I’m not able to find any good discussion about how to enumerate all children and calculate which is topmost.
Maybe the
WindowFromPointAPI function fits the bill?The documentation does not explicitly mention Z ordering, but I can assure you from first-hand experience that “contains” implicitly means that no other window is in front.
There are several more of these, with slightly different behaviour:
ChildWindowFromPoint,ChildWindowFromPointExandRealChildWindowFromPoint.