gpt4 book ai didi

delphi - 当 vcl 样式从 NC 区域删除时,TMainMenu 不显示

转载 作者:行者123 更新时间:2023-12-03 15:23:40 26 4
gpt4 key购买 nike

我使用此代码从表单的非客户区域中删除 vcl 样式。

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);

在应用此样式 Hook 之前,表单看起来像

enter image description here

及之后

enter image description here

正如您所看到的,菜单消失了,问题是:我该如何解决这个问题?我的意思是如何从表单的非客户区域删除 vcl 样式而不删除 TMainMenu?

最佳答案

当您使用 vcl 样式时,TMain 菜单由 TMainMenuBarStyleHook vcl 样式 Hook 绘制,该 Hook 在 TFormStyleHook(表单的 Hook )内部定义,在这种情况下,因为您没有使用此 Hook ,所以没有代码来绘制 TMainMenu。

两种可能的解决方案是

1) 在 TFormStyleHookNC 内部为 TMainMenu 实现 vcl 样式 Hook ,就像 TFormStyleHook 一样。

2)或者更好地使用 TActionMainMenuBar 组件而不是 TMainMenu,该组件与 vcl 样式集成得很好(检查下一个示例图像)。

enter image description here

关于delphi - 当 vcl 样式从 NC 区域删除时,TMainMenu 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11963441/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com