Einzelnen Beitrag anzeigen

hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.270 Beiträge
 
Delphi 10.4 Sydney
 
#8

AW: TCheckBox.Color über WM_CTLCOLOR

  Alt 2. Aug 2016, 08:43
Hallo,
und hier das fertige Endprodukt mit dynamisch erzeugter CheckBox3.
Tag=1 bedeutet "rote Schrift"

Delphi-Quellcode:
unit Unit101;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm101 = class(TForm)
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure WMCTLColor(var msg: TWMCtlColorStatic); message WM_CTLCOLORSTATIC;
  public
    { Public-Deklarationen }
  end;

var
  Form101: TForm101;

implementation

{$R *.dfm}

uses
  UxTheme;

{ TForm101 }

procedure TForm101.FormCreate(Sender: TObject);
var
  CheckBox3: TCheckBox;
begin
  SetWindowTheme(CheckBox2.Handle, '', '');

  CheckBox3 := TCheckBox.Create(Self);
  CheckBox3.Parent := Self;
  CheckBox3.Caption := 'CheckBox3';
  CheckBox3.Tag := 1;
  CheckBox3.Name := 'CheckBox3';
  SetWindowTheme(CheckBox3.Handle, '', '');
end;

procedure TForm101.WMCTLColor(var msg: TWMCtlColorStatic);
var
  sCompText: array[0..255] of Char;
  Comp: TComponent;
  CheckBox: TCheckBox;
begin
  inherited ;

  //if msg.ChildWnd=CheckBox2.Handle then
  begin
    SendMessage(msg.ChildWnd, WM_GETTEXT, SizeOf(sCompText), Integer(@sCompText[0]));

    if sCompText<>'then
    begin
      Comp := FindComponent(sCompText);
      if Comp<>nil then
      begin
        if Comp is TCheckBox then
        begin
          CheckBox := TCheckBox(Comp);
          if CheckBox.Tag=1 then
          begin
            SetTextColor(Msg.ChildDC,clRed);
          end;
        end;
      end;
    end;
  end;
end;

end.
Heiko

Geändert von hoika ( 2. Aug 2016 um 08:45 Uhr)
  Mit Zitat antworten Zitat