Einzelnen Beitrag anzeigen

4dk2

Registriert seit: 4. Sep 2007
176 Beiträge
 
#1

[XE4] Styles, TListbox und WS_EX_COMPOSITED

  Alt 1. Dez 2015, 14:18
Hallo zusammen,
meine Anwendung soll einen Standart Style von Delphi. (z.b. Auric) bekommen.
Nun habe das problem, dass ich gerne alle Controls mit der Option WS_EX_COMPOSITED ausstatten würde.
Warum?
Durch diverse experimente mit den Styles ist herausgekommen, dass durch das WS_EX_COMPOSITED flag das zeichnen der Controls wesentlich schneller abläuft,
und auch flackern, z.b. bei resize, show/hide beseitigt wird. (gibt da diverse Artikel via Google)

Bisher ist auch alles Ok, bis auf die TListbox.

Wenn ich bei der, oder z.b. einem Parent Panel die option setzte, wird die listbox nicht mehr richtig gezeichnet und die Anwendung reagiert teilweise garnicht mehr.
Jedoch erst wenn die Scrollbars sichtbar werden!

Hier der Code (oder im anhang das gesamte TestProjekt)

Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Panel3: TPanel;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



procedure SetComposited(WinControl: TWinControl; Value: boolean);
var
  ExStyle, NewExStyle: DWORD;
begin
  if WinControl.InheritsFrom(TCustomForm) then exit;
  if WinControl.InheritsFrom(TCustomListBox) then exit;

  ExStyle := GetWindowLong(WinControl.Handle, GWL_EXSTYLE);
  if Value then
  begin
    NewExStyle := ExStyle or WS_EX_COMPOSITED;
  end
  else
  begin
    NewExStyle := ExStyle and not WS_EX_COMPOSITED;
  end;
  if NewExStyle <> ExStyle then
  begin
    SetWindowLong(WinControl.Handle, GWL_EXSTYLE, NewExStyle);
  end;
end;


procedure SetAllComposited(WinControl: TWinControl;AValue:boolean);
var
  i: Integer;
  NewExStyle: DWORD;
begin
  //ifs für fehler bei listbox...
  if not WinControl.InheritsFrom(TListBox) then //das bringt nix...
  if not WinControl.InheritsFrom(TCustomForm) then //das bringt nix...
    SetComposited(WinControl, AValue);
  for i := 0 to WinControl.ControlCount-1 do
    if WinControl.Controls[i] is TWinControl then
      SetAllComposited(TWinControl(WinControl.Controls[i]),AValue);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;

begin
  SetComposited(Panel1,true);
  SetComposited(self,true);
  SetComposited(ListBox1,false);
  for I := 1 to 200 do
    ListBox1.AddItem('asd',nil);
end;

end.
Angehängte Dateien
Dateityp: zip XEStyleTest_Listbox.zip (139,9 KB, 2x aufgerufen)
  Mit Zitat antworten Zitat