In FireMonkey (FMX), every TControl component has a HitTest property that allows me to enable or disable mouse events on the component.
Is there something like this in VCL? I tried searching and looking for it, but I can't find a HitTest property anywhere.
If there isn't HitTest for VCL, how can the same be achieved? Can someone provide a code example on how to do it in VCL perhaps?
I am using Embarcadero Delphi 12.
There is no such property in VCL.
All FMX controls are entirely custom made with very little management by the OS, so mouse handling is managed by FMX itself, thus exposing a
HitTestproperty is trivial for FMX to do.But in VCL, only
TGraphicControldescendants are implemented like that.TWinControldescendants, on the other hand, are wrappers for Win32HWNDwindows and so mouse handling is largely managed by the OS instead.For windowed VCL controls, you will have to manually subclass each control as needed to handle the Win32
WM_NCHITTESTmessage directly. The VCL doesn't normally handle that message (except in a few select cases).For example:
For a graphic control, you would have to subclass its windowed
Parentcontrol instead.However, be careful with how you modify the default behavior of
WM_NCHITTEST:WM_NCHITTEST is for hit-testing, and hit-testing can happen for reasons other than the mouse being over your window