简体   繁体   English

如何将Form Border更改为Windows Basic而不是Aero Style?

[英]How to change Form Border to Windows Basic instead of Aero Style?

I want to know if it is possible, and if so how to change a forms border style to Windows Basic instead of the Aero theme? 我想知道是否可能,如果可以,如何将表单边框样式更改为Windows Basic而不是Aero主题? Obviously taking into consideration whether Aero is enabled or not in the first place, if it is not then there is no need to attempt to change the border style. 显然,首先考虑Aero是否启用,如果不启用,则无需尝试更改边框样式。

So instead of: 所以代替:

在此输入图像描述

We would have: (mock-up image) 我们会:(模拟图像)

在此输入图像描述

MDI Applications already do this for the child forms but I don't want or need an MDI Application. MDI应用程序已经为子表单执行此操作,但我不想要或不需要MDI应用程序。 I tried looking through the source of Vcl.Forms to see if I could find anything related but I was unable to - I could be wrong but I actually think the way that MDI Forms are drawn is determined by Windows, not Delphi. 我试着查看Vcl.Forms的来源,看看我是否能找到任何相关但我无法 - 我可能是错的但我实际上认为绘制MDI表单的方式是由Windows而不是Delphi决定的。

DSiWin32 contains a couple of functions related to Aero, such as determining whether or not Aero is enabled or not, as well as been able to Enable and Disable Aero - However this appears to be a system wide change and not on a per Form/Window basis, it also causes a screen delay while the theme is changed which is not good. DSiWin32包含一些与Aero相关的功能,例如确定Aero是否已启用,以及能够启用和禁用Aero - 但这似乎是系统范围的更改,而不是每个窗体/窗口基础,它也导致屏幕延迟,而主题改变,这是不好的。

I am unsure where to go from at this point. 我不确定在这一点上去哪里。 Is there something simple I may have overlooked? 我可能忽略了一些简单的事情吗? Do we need to create and override our own TForm with some specific flags etc to achieve this, or possibly there is a way to change the form style at any point, eg Enable/Disable Aero for the form? 我们是否需要创建和覆盖我们自己的TForm以及一些特定的标志等来实现这一点,或者可能有一种方法可以在任何时候改变表单样式,例如为表单启用/禁用Aero?

Simply put, I want to know if it is possible without resorting to MDI Applications, can we change any Form/Window Border to Windows Basic theme, provided Aero is enabled in the first place? 简单地说,我想知道是否可以不使用MDI应用程序,我们是否可以将任何窗体/窗口边框更改为Windows Basic主题,只要首先启用Aero?

Call DwmSetWindowAttribute passing the DWMWA_NCRENDERING_POLICY attribute with a value of DWMNCRP_DISABLED . 调用DwmSetWindowAttribute传递DWMWA_NCRENDERING_POLICY属性,其值为DWMNCRP_DISABLED

type
  TForm1 = class(TForm)
  protected
    procedure CreateWnd; override;
  end;

procedure TForm1.CreateWnd;
var
  Policy: Integer;
begin
  inherited;
  Policy := DWMNCRP_DISABLED;
  DwmSetWindowAttribute(WindowHandle, DWMWA_NCRENDERING_POLICY, @Policy, 
    SizeOf(Policy));
end;

I've ignored error checking here. 我在这里忽略了错误检查。 You may determine that responding to errors is worthwhile. 您可以确定响应错误是值得的。 I also didn't do any testing whether or not the operating system supports this function call, but again you could choose to do so if you need to support XP. 我也没有做任何测试操作系统是否支持这个函数调用,但如果你需要支持XP,你也可以选择这样做。

Note that CreateWnd is the right place to call DwmSetWindowAttribute . 请注意, CreateWnd是调用DwmSetWindowAttribute的正确位置。 The window handle is created in CreateWnd , and we want to apply this policy as soon as possible. 窗口句柄是在CreateWnd创建的,我们希望尽快应用此策略。 Putting the code in CreateWnd also makes it robust against re-creation. 将代码放在CreateWnd也可以使其在重新创建时更加强大。

Normal Aero form: 普通航空表格:

在此输入图像描述

Form with the call to DwmSetWindowAttribute : 调用DwmSetWindowAttribute

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM