Delphi/Lazarus: Get Handle of Window under Mouse Cursor
Question by Guest | Last update on 2023-03-22 | Created on 2015-12-22
I would like to specify the window that is currently under the mouse cursor using Delphi or Lazarus. The whole thing should work under the operating system Windows and it should work systemwide, not only in my own application. I need the Handle of that window.
Is this possible in some way? And if yes, can someone tell me how to do it?
Related Topics
Delphi/Lazarus: How to set up a Link to a Website in an Application
Tutorial | 0 Comments
Pipette: Fetch Colors from all over the Screen
Tutorial | 0 Comments
Delphi/Lazarus: Is the ALT, SHIFT or CTRL key pressed?
Tutorial | 0 Comments
Delphi: GetCursorPos problem on Windows 8.1 with scaling
Open Question | 1 Answer
Delphi: System-Wide HotKey
Tutorial | 1 Comment
Delphi/Lazarus: Retrieve Cursor Position relative to Form/Window
Tip | 0 Comments
Delphi: Global Treatment of Errors (Exceptions)
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
First of all, you have to determine the current mouse position. This can be done using the function GetCursorPos(). After that, you can use the function WindowFromPoint() to specify the window at this position.
Here is an example:
Because both functions may fail, you should implement conditions like I have done in the example. Only if you are sure that the Handle is not 0, that means, a window was found, you should go on and use the Handle. In the example above, we are sending a message to the corresponding window.
Last update on 2023-03-22 | Created on 2015-12-24