2012-03-25 7 views
7

È un errore VclStyle? T^TI cercato di trovare l'elenco BugFix (http://edn.embarcadero.com/article/42090/) ma non possoBug di VclStyle? TProgressBar.Style: = pbstMarQuee Non funziona

  1. File> Nuovo> VCL applicazione
  2. TProgressBar messo principale forma> TProgressBar .style: = pbstMarQuee
  3. opzione di progetto> Aspetto> set Custom Style> set stile predefinito
  4. Ctrl + F9

ProgressBar non funziona

Siamo spiacenti. Il mio inglese non funziona :(

risposta

13

Questa è una funzionalità non implementata nello TProgressBarStyleHook. Purtroppo Windows non invia alcun messaggio al controllo della barra di avanzamento per indicare se la posizione della barra cambia quando è in marquee mode, quindi è necessario implementare la vostra auto un meccanismo per imitare lo stile PBS_MARQUEE, questo può essere fatto facilmente la creazione di un nuovo gancio stile e con un TTimer all'interno del gancio stile.

controllare questa implementazione di base del gancio di stile

uses 
    Vcl.Styles, 
    Vcl.Themes, 
    Winapi.CommCtrl; 

{$R *.dfm} 

type 
TProgressBarStyleHookMarquee=class(TProgressBarStyleHook) 
    private 
    Timer : TTimer; 
    FStep : Integer; 
    procedure TimerAction(Sender: TObject); 
    protected 
    procedure PaintBar(Canvas: TCanvas); override; 
    public 
    constructor Create(AControl: TWinControl); override; 
    destructor Destroy; override; 
end; 


constructor TProgressBarStyleHookMarquee.Create(AControl: TWinControl); 
begin 
    inherited; 
    FStep:=0; 
    Timer := TTimer.Create(nil); 
    Timer.Interval := 100;//TProgressBar(Control).MarqueeInterval; 
    Timer.OnTimer := TimerAction; 
    Timer.Enabled := TProgressBar(Control).Style=pbstMarquee; 
end; 

destructor TProgressBarStyleHookMarquee.Destroy; 
begin 
    Timer.Free; 
    inherited; 
end; 

procedure TProgressBarStyleHookMarquee.PaintBar(Canvas: TCanvas); 
var 
    FillR, R: TRect; 
    W, Pos: Integer; 
    Details: TThemedElementDetails; 
begin 
    if (TProgressBar(Control).Style=pbstMarquee) and StyleServices.Available then 
    begin   
    R := BarRect; 
    InflateRect(R, -1, -1); 
    if Orientation = pbHorizontal then 
     W := R.Width 
    else 
     W := R.Height; 

    Pos := Round(W * 0.1); 
    FillR := R; 
    if Orientation = pbHorizontal then 
    begin 
     FillR.Right := FillR.Left + Pos; 
     Details := StyleServices.GetElementDetails(tpChunk); 
    end 
    else 
    begin 
     FillR.Top := FillR.Bottom - Pos; 
     Details := StyleServices.GetElementDetails(tpChunkVert); 
    end; 

    FillR.SetLocation(FStep*FillR.Width, FillR.Top); 
    StyleServices.DrawElement(Canvas.Handle, Details, FillR); 
    Inc(FStep,1); 
    if FStep mod 10=0 then 
    FStep:=0; 
    end 
    else 
    inherited; 
end; 

procedure TProgressBarStyleHookMarquee.TimerAction(Sender: TObject); 
var 
    Canvas: TCanvas; 
begin 
    if StyleServices.Available and (TProgressBar(Control).Style=pbstMarquee) and Control.Visible then 
    begin 
    Canvas := TCanvas.Create; 
    try 
     Canvas.Handle := GetWindowDC(Control.Handle); 
     PaintFrame(Canvas); 
     PaintBar(Canvas); 
    finally 
     ReleaseDC(Handle, Canvas.Handle); 
     Canvas.Handle := 0; 
     Canvas.Free; 
    end; 
    end 
    else 
    Timer.Enabled := False; 
end; 

initialization 

TStyleManager.Engine.RegisterStyleHook(TProgressBar, TProgressBarStyleHookMarquee); 

end. 

È puoi controllare una demo di questo porcile le hook here

+0

Dove stai liberando il timer? – Pateman

+0

@Pateman Oops, codice modificato. Buona pesca. :) – RRUZ

+0

+1, sembra decente ora! – Pateman

Problemi correlati