AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

TCheckBox.Color über WM_CTLCOLOR

Ein Thema von hoika · begonnen am 2. Aug 2016 · letzter Beitrag vom 2. Aug 2016
Antwort Antwort
hoika

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

TCheckBox.Color über WM_CTLCOLOR

  Alt 2. Aug 2016, 07:43
Hallo,
das CheckBox.Color keine Wirkung hat, ist ja bekannt.

Lösung 1: andere Komponente
Lösung 2: CheckBox ohne Caption + Label davor
Lösung 3: WM_CTLCOLOR überschreiben

Lösung 3 klappt bei mir irgendwie nicht

Die Methode wird gar nicht aufgerufen!
Ich bin mir sicher, dass ich das schon mal geschafft hatte.

Weiss jemand Rat?


Delphi-Quellcode:
unit Unit101;

interface

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

type
  TForm101 = class(TForm)
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
  private
    { Private-Deklarationen }
    procedure WMCTLColor(var msg: TWMCtlColor); message WM_CTLCOLOR;
  public
    { Public-Deklarationen }
  end;

var
  Form101: TForm101;

implementation

{$R *.dfm}

{ TForm101 }

procedure TForm101.WMCTLColor(var msg: TWMCtlColor);
begin
  inherited ;

  //SetTextColor(Msg.wParam,RGB(0,$80,0));
  //Exit;


  if msg.ChildWnd=CheckBox2.Handle then
  begin
    msg.Result := CreateSolidBrush(RGB(255, 255, 0));
  end;
  
end;

end.
Heiko
  Mit Zitat antworten Zitat
Benutzerbild von Bernhard Geyer
Bernhard Geyer

Registriert seit: 13. Aug 2002
17.171 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: TCheckBox.Color über WM_CTLCOLOR

  Alt 2. Aug 2016, 07:47
Leg dir halt einfach ein Panel hinter die Checkbox.
oder mach ein Composit-Control aus Panel + Checkbox als TMyCheckboxWithColor
Windows Vista - Eine neue Erfahrung in Fehlern.
  Mit Zitat antworten Zitat
CarlAshnikov

Registriert seit: 18. Feb 2011
Ort: Erfurt
108 Beiträge
 
Delphi XE5 Enterprise
 
#3

AW: TCheckBox.Color über WM_CTLCOLOR

  Alt 2. Aug 2016, 07:52
Hier steht, dass die Nachricht nur in 16-bit Windows verwendet wurde und durch andere ersetzt ist:

https://msdn.microsoft.com/de-de/lib...(v=vs.85).aspx
Sebastian
Das kann ja wohl nicht var sein!
  Mit Zitat antworten Zitat
hoika

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

AW: TCheckBox.Color über WM_CTLCOLOR

  Alt 2. Aug 2016, 07:59
Hallo,

ja, schon bemerkt.

    procedure WMCTLColor(var msg: TWMCtlColorStatic); message WM_CTLCOLORSTATIC; Aber was muss ich machen, um jetzt die Farbe zu ändern.
Ich bekomme immer Bereichsfehler.
Das kann doch nicht sooo schwer sein, verd...

Delphi-Quellcode:
procedure TForm101.WMCTLColor(var msg: TWMCtlColorStatic);
begin
  inherited ;

  //SetTextColor(Msg.ChildDC,RGB(0,$80,0));
  //Exit;

  //SetTextColor(Msg.wParam,RGB(0,$80,0));


  if msg.ChildWnd=CheckBox2.Handle then
  begin
    //msg.Result := CreateSolidBrush(RGB(0, 0, 0));
    //SetTextColor(Msg.ChildDC,RGB(0,$80,0)); // <<-- Bereichsfehler !

    msg.Result := GetStockObject(NULL_BRUSH);
  end;

end;
Heiko
  Mit Zitat antworten Zitat
hoika

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

AW: TCheckBox.Color über WM_CTLCOLOR

  Alt 2. Aug 2016, 08:10
Hm,
alles sehr merkwürdig.

aktueller Stand mit TMessage
Ohne das try except immer noch ein Bereichsfehler


Delphi-Quellcode:
procedure TForm101.WMCTLColor(var msg: TMessage);
var
  MyDC: HDC;
begin
  inherited ;

  //SetTextColor(Msg.ChildDC,RGB(0,$80,0));
  //Exit;

  //SetTextColor(Msg.wParam,RGB(0,$80,0));


  //if msg.ChildWnd=CheckBox2.Handle then
  if msg.lParam=CheckBox2.Handle then
  begin
    try
    //SetTextColor(Msg.ChildDC,RGB(0,$80,0));
      //SetTextColor(Msg.ChildDC,ColorToRGB(clRed));
      //msg.Result := CreateSolidBrush(RGB(0, $80, 0));
      //msg.Result := CreateSolidBrush(ColorToRGB(clRed));
      //msg.Result := CreateSolidBrush(RGB(255, 0, 0));

      MyDC := HDC(msg.wParam);

      //SetTextColor(MyDC, ColorToRGB(clRed));

      msg.Result := CreateSolidBrush(ColorToRGB(clRed));

    //msg.Result := GetStockObject(NULL_BRUSH);
    except

    end;
  end;
end;
Heiko
  Mit Zitat antworten Zitat
Benutzerbild von uligerhardt
uligerhardt

Registriert seit: 19. Aug 2004
Ort: Hof/Saale
1.735 Beiträge
 
Delphi 2007 Professional
 
#6

AW: TCheckBox.Color über WM_CTLCOLOR

  Alt 2. Aug 2016, 08:19
Ich könnte mir vorstellen, dass das nicht zusammen mit Windows-Themes funktioniert.
Uli Gerhardt
  Mit Zitat antworten Zitat
hoika

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

AW: TCheckBox.Color über WM_CTLCOLOR

  Alt 2. Aug 2016, 08:28
Hallo,
ja daran lag es u.a.
vielleicht braucht ja jemand auch die Lösung unten.

Der Bereichsfehler kam daher, dass ich immer RGB-Werte erzeugen wollte,
das SetTextColor klappt aber auch mit den TColor-Werten direkt.

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);
begin
  SetWindowTheme(CheckBox2.Handle, '', '');
  // SetWindowTheme(CheckBox2.Handle, nil, nil); ist falsch !
end;

procedure TForm101.WMCTLColor(var msg: TWMCtlColorStatic);
begin
  inherited ;

  if msg.ChildWnd=CheckBox2.Handle then
  begin
    SetTextColor(Msg.ChildDC,clRed);
  end;
end;

end.
Heiko
  Mit Zitat antworten Zitat
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
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:58 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz