The generic hit testing can be done by doing something like this:
- each control should have a geometry of it's layout. Either a basic rectangle, ellipse, irregular shape. Then, the control manager does hit testing against them. Then orders possible matches by zorder
- just hit-tests against them in zorder to prevent the sorting step.
You should store control hierarchy zordered anyways, and this, by itself, skips the sorting.
Controls don't need to know about their location but NEED to know their sizes (if rectangular) and/or shapes. And the manager knows the location and a bounding rectangle. Combine these elements and you can the hit-test. First make sure the point falls in the bounding rectangle and only then hit-test against the control's geometry. Before hit-testing, update the HWND client point to the control client point by subtracting the control client offsets known by the control manager.
That's how I'm (planning to) doing it. But I'm making it windowsless. If each control is in a child HWND of its own, life is so much easier!
PS: You can mail me if you want to exchange ideas. You can find my email if you want to. ;)