views:

159

answers:

2

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.

+2  A: 

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
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
A: 

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