tfinniga
tfinniga

Reputation: 6849

Find which MFC child window would receive a mouse click

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.

Upvotes: 3

Views: 2030

Answers (2)

Aric TenEyck
Aric TenEyck

Reputation: 8032

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.

Upvotes: 0

Thomas
Thomas

Reputation: 181745

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.

Upvotes: 4

Related Questions