How detect when a vcl style is changed?

前端 未结 1 614
孤街浪徒
孤街浪徒 2021-01-19 13:42

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

1条回答
  •  无人及你
    2021-01-19 14:17

    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.
    

    0 讨论(0)
提交回复
热议问题