Search code examples
delphifocusmouse-cursorsetfocus

How do I get the Control that is under the cursor in Delphi?


I need the opposite information that the question "How to get cursor position on a control?" asks.

Given the current cursor position, how can I find the form (in my application) and the control that the cursor is currently over? I need the handle to it so that I can use Windows.SetFocus(Handle).

For reference, I'm using Delphi 2009.


Solution

  • I think FindVCLWindow will meet your needs. Once you have the windowed control under the cursor you can walk the parent chain to find the form on which the window lives.