同一窗体类的不同实例如何使用不同的窗口类样式?

发布于 2024-08-01 19:25:19 字数 755 浏览 4 评论 0原文

我尝试使用以下技术来启用/禁用窗口的阴影效果:(CreateParams 当然被覆盖。TToolWindow 源自 TForm)。

procedure TToolWindow.CreateParams(var Params: TCreateParams); 
var
  LShadow: boolean;

begin
  inherited;

  if (Win32Platform = VER_PLATFORM_WIN32_NT)
    and ((Win32MajorVersion > 5)
    or ((Win32MajorVersion = 5) and (Win32MinorVersion >= 1))) then //Win XP or higher
      if SystemParametersInfo(SPI_GETDROPSHADOW, 0, @LShadow, 0) then
      begin
        if LShadow and HasShadow then
          Params.WindowClass.Style := Params.WindowClass.Style or CS_DROPSHADOW;
      end;
end;

虽然这对于 TToolWindow 类的第一个实例可以正常工作,但以下实例将保留第一个实例的设置,而不管 HasShadow 的值(这是 TToolWindow 类的已发布属性)如何。

如何在 TToolWindow 的不同实例上具有不同的阴影设置?

TIA

I try to use the following technique in order to enable/disable the shadow effect for a window: (The CreateParams is of course overriden. The TToolWindow descends from TForm).

procedure TToolWindow.CreateParams(var Params: TCreateParams); 
var
  LShadow: boolean;

begin
  inherited;

  if (Win32Platform = VER_PLATFORM_WIN32_NT)
    and ((Win32MajorVersion > 5)
    or ((Win32MajorVersion = 5) and (Win32MinorVersion >= 1))) then //Win XP or higher
      if SystemParametersInfo(SPI_GETDROPSHADOW, 0, @LShadow, 0) then
      begin
        if LShadow and HasShadow then
          Params.WindowClass.Style := Params.WindowClass.Style or CS_DROPSHADOW;
      end;
end;

While this works ok for the first instance of the TToolWindow class, the following instances keep the setting from the first instance, regardless of the value of HasShadow (which is a published property of the TToolWindow class).

How can I have different shadow settings on different instances of TToolWindow?

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想挽留 2024-08-08 19:25:19

每次创建给定类的第一个实例时,VCL 都会动态注册表单类所需的窗口类。 这就解释了为什么 TToolWindow 的所有辅助实例都具有与第一个实例相同的阴影,而不管 HasShadow 值如何。 您正在创建相同窗口类的窗口,因此它们都具有相同的类样式。

您可以做的是注册两个类,一个带有阴影,另一个没有阴影。 如果类名与先前注册的类不同,VCL 将注册一个新的窗口类。

像这样的事情:

procedure TToolWindow.CreateParams(var Params: TCreateParams); 
var
  LShadow: boolean;
begin
  inherited;

  if (Win32Platform = VER_PLATFORM_WIN32_NT)
    and ((Win32MajorVersion > 5)
    or ((Win32MajorVersion = 5) and (Win32MinorVersion >= 1))) 
  then begin
    //Win XP or higher
    if SystemParametersInfo(SPI_GETDROPSHADOW, 0, @LShadow, 0)
      and LShadow and HasShadow
    then begin
      Params.WindowClass.Style := Params.WindowClass.Style or CS_DROPSHADOW;
      StrLCopy(Params.WinClassName, 'TDelphiToolWindowWithShadow', 63);
    end else begin
      Params.WindowClass.Style := Params.WindowClass.Style and not CS_DROPSHADOW;
      StrLCopy(Params.WinClassName, 'TDelphiToolWindowNoShadow', 63);
    end;
  end;
end;

The VCL registers the necessary window classes for form classes on the fly, once each time the first instance of a given class is created. That explains why all secondary instances of your TToolWindow have the same shadow as the first instance, regardless of the HasShadow value. You are creating windows of the same window class, so they all have the same class style.

What you could do is registering two classes, one with the drop shadow, the other without it. The VCL will register a new window class if the class name is different from the previously registered class.

Something like this:

procedure TToolWindow.CreateParams(var Params: TCreateParams); 
var
  LShadow: boolean;
begin
  inherited;

  if (Win32Platform = VER_PLATFORM_WIN32_NT)
    and ((Win32MajorVersion > 5)
    or ((Win32MajorVersion = 5) and (Win32MinorVersion >= 1))) 
  then begin
    //Win XP or higher
    if SystemParametersInfo(SPI_GETDROPSHADOW, 0, @LShadow, 0)
      and LShadow and HasShadow
    then begin
      Params.WindowClass.Style := Params.WindowClass.Style or CS_DROPSHADOW;
      StrLCopy(Params.WinClassName, 'TDelphiToolWindowWithShadow', 63);
    end else begin
      Params.WindowClass.Style := Params.WindowClass.Style and not CS_DROPSHADOW;
      StrLCopy(Params.WinClassName, 'TDelphiToolWindowNoShadow', 63);
    end;
  end;
end;
吝吻 2024-08-08 19:25:19

只是猜测...后续实例是 TToolWindow 的子级吗? 也许他们继承了父母的风格。

编辑:实际上,我在网上读到,如果你给项目一个 WS_CHILD 样式,它会忽略 CS_DROPSHADOW。 因此,如果其他方法都失败,这可能是解决问题的一种方法。

Just a guess... are the subsequent instances children of your TToolWindow? Perhaps they are inheriting the style from the parent.

Edit: Actually, I read online that if you give items a WS_CHILD style, it will ignore CS_DROPSHADOW. So that might be one way to hack around your issue if all else fails.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文