TMainMenu is not shown when the vcl styles is removed from the NC Area

你。 提交于 2020-01-02 06:33:52

问题


I'm using this code to remove the 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 to apply this style hook the form looks like

and after

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


回答1:


When you uses the vcl styles, the TMain menu is drawn by the TMainMenuBarStyleHook vcl style hook, which is defined inside of the TFormStyleHook (the hook of the forms), in this case because you are not using this hook there is not code to draw the TMainMenu.

Two possible solutions are

1) Implement the vcl style hook for the TMainMenu inside of the TFormStyleHookNC , just like the TFormStyleHook does.

2)or even better use a TActionMainMenuBar component instead of a TMainMenu, this component is very well integrated with the vcl styles (check the next sample image).



来源:https://stackoverflow.com/questions/11963441/tmainmenu-is-not-shown-when-the-vcl-styles-is-removed-from-the-nc-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!