delphidelphi-xemouseclick-eventonmouseclick

Any way to detect if a form has been clicked?


Delphi XE

Is there any way to detect if a form has received a mouse click? The OnClick event in the form is only triggered on empty parts of the form. Any parts which have controls won't respond.


Solution

  • You'll need to filter queued messages to detect mouse events at a global level.

    1. Add a handler for TApplication.OnMessage.
    2. Listen to WM_MOUSEDOWN or WM_MOUSEUP as you please, and respond if the target window handle is that of the form, or a child control.
    3. Make sure you leave the Handled parameter of the message as False so that the message is delivered to its target.

    If you really are trying to detect form activation, use OnActivate.