How detect when a vcl style is changed?

China☆狼群 提交于 2020-03-16 05:57:11

问题


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?


回答1:


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.

Try this sample Code.

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.


来源:https://stackoverflow.com/questions/10375879/how-detect-when-a-vcl-style-is-changed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!