Delphi FMX – click through form. HitTest not available

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,203
Credits
4,034
Delphi FMX – click through form. HitTest not available
Scott Hollows
June 14, 2020

[SHOWTOGROUPS=4,20]
Delphi FMX – click through form. HitTest not available
Scott Hollows

Create a Delphi FireMonkey (FMX) form that the user can click through

This post shows you how to create a Delphi FireMonkey (FMX) form that the user can click through as if the form did not exist.

The form can be transparent or not transparent
Many FMX components have a HitTest property. If you set this to FALSE, the mouse will click through the component as if it is not there
Unfortunately, TForm does not have this HitTest property, but dont panic because you can achieve the same thing with a few lines of code


Код:
// uses FMX.Platform.Win
//     ,Windows;

SetWindowLong(
   FmxHandleToHWND(Handle) // convert FMX handle to Windows hwnd handle
  ,GWL_EXSTYLE
  ,WS_EX_LAYERED or WS_EX_TRANSPARENT
  );

If it doesn’t work …

Some window operations will prevent the code from working. As a simple workaround make sure you call the above code after you do any of the following

  • Making the window OnTop
    self.FormStyle := TFormStyle.StayOnTop;
  • Bringing the window to the front
    self.BringToFront;

As a general guideline, if it does not work make sure that you call SetWindowLong to enable the click through as the last thing that you do.

Platforms

This solution will only work on Microsoft Windows.
[/SHOWTOGROUPS]