TMainMenu is not displayed when vcl styles are removed from the NC scope

I use this code to remove vcl styles from the non-client area of ​​a form.

type
  TFormStyleHookNC= class(TMouseTrackControlStyleHook)
  protected
    procedure PaintBackground(Canvas: TCanvas); override;
    constructor Create(AControl: TWinControl); override;
  end;

constructor TFormStyleHookNC.Create(AControl: TWinControl);
begin
  inherited;
  OverrideEraseBkgnd := True;
end;

procedure TFormStyleHookNC.PaintBackground(Canvas: TCanvas);
var
  Details: TThemedElementDetails;
  R: TRect;
begin
  if StyleServices.Available then
  begin
    Details.Element := teWindow;
    Details.Part := 0;
    R := Rect(0, 0, Control.ClientWidth, Control.ClientHeight);
    StyleServices.DrawElement(Canvas.Handle, Details, R);
  end;
end;


initialization
 TStyleManager.Engine.RegisterStyleHook(TForm3, TFormStyleHookNC);

Before applying this style, the form looks like

enter image description here

and after

enter image description here

As you can see, the menu disappears, the question arises: how can I fix this? I mean, how can I remove vcl styles from the non-client area of ​​a form without removing TMainMenu?

+4
source share
1 answer

When you use vcl styles, the TMain menu is drawn with a vcl style TMainMenuBarStyleHookhook that is defined internally TFormStyleHook(forms hook), in this case, because you are not using this Hook does not contain code for drawing TMainMenu.

Two possible solutions:

1) vcl TMainMenu TFormStyleHookNC, TFormStyleHook.

2) TActionMainMenuBar TMainMenu, vcl ( ).

enter image description here

+7

All Articles