3

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.

tfinniga
  • 6,693
  • 3
  • 32
  • 37

2 Answers2

4

Maybe the WindowFromPoint API function fits the bill?

Retrieves a handle to the window that contains the specified point.

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, ChildWindowFromPointEx and RealChildWindowFromPoint.

Thomas
  • 174,939
  • 50
  • 355
  • 478
  • Thanks, this did it. I also found some good information (specifically, to use the GetCursorPos API) here: http://www.codeproject.com/KB/dialog/windowfinder.aspx – tfinniga May 19 '10 at 19:55
0

It's been a long time since I did MFC, but I think that HitTest is the term you're looking for. A quick trawl through MSDN indicates that most windows implement a HitTest function that returns information about a particular point.

Aric TenEyck
  • 8,002
  • 1
  • 34
  • 48