2012-08-15 82 views
4

我使用此代码从窗体的非客户区域中删除vcl样式。当从NC区域删除vcl样式时不显示TMainMenu

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

之前应用这种风格挂钩的形式看起来像

enter image description here

enter image description here

正如你可以看到菜单消失,现在的问题是:如何我可以解决这个问题?我的意思是,如何在不删除TMainMenu的情况下从表单的非客户区删除vcl样式?

回答

7

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

两个可能的解决方案是

1)实现对TMainMenu的VCL风格钩TFormStyleHookNC里面,就像TFormStyleHook一样。

2)或甚至更好地使用TActionMainMenuBar组件而不是TMainMenu,该组件非常好地与vcl样式集成(查看下一个示例图像)。

enter image description here