如何检测何时更改vcl样式? [英] How detect when a vcl style is changed?

查看:105
本文介绍了如何检测何时更改vcl样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了多个WinAPi函数,这些函数需要使用表单的Handle才能正常工作,因此,当更改vcl样式时,会重新创建表单的句柄,因此对这些函数的许多调用都会停止工作.所以我需要一种方法来检测当前vcl样式何时被修改(更改)以更新对这些函数的调用.问题是How detect when a vcl style is changed?

I use several WinAPi functions which needs the Handle of the form in order to work, due which the handle of the form is recreated when the vcl styles is changed many of the calls to these functions stop working. So I need a way to detect when the current vcl style is modified (changed) in order to update the calls to these functions.The question is How detect when a vcl style is changed?

推荐答案

通过 CM_CUSTOMSTYLECHANGED 消息发送给所有人应用程序的表单,然后在表单的WndProc方法中处理messgae,然后发送CM_STYLECHANGED消息以通知哪个vcl样式已更改,因此您可以收听

When a vcl style is changed via the TStyleManager.SetStyle method a CM_CUSTOMSTYLECHANGED message is sent to all the forms of the application, then that messgae is processed in the WndProc method of the form and then a CM_STYLECHANGED message is sent to inform which the vcl style has changed, so you can listen the CM_STYLECHANGED message to detect when a vcl style has changed.

尝试此示例代码.

type
  TForm17 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure CMStyleChanged(var Message: TMessage); message CM_STYLECHANGED;
  public
    { Public declarations }
  end;

var
  Form17: TForm17;

implementation

uses
 Vcl.Themes;

{$R *.dfm}

procedure TForm17.Button1Click(Sender: TObject);
begin
   TStyleManager.SetStyle('Carbon');
end;

procedure TForm17.CMStyleChanged(var Message: TMessage);
begin
  ShowMessage('The vcl style has changed');
end;

end.

这篇关于如何检测何时更改vcl样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆