[RESUELTO] ¿Cómo hacer una barra de progreso sin fin?
#1
Escrito 19 julio 2009 - 04:48
Saludos.
#2
Escrito 19 julio 2009 - 07:27
const {$EXTERNALSYM PBS_MARQUEE} PBS_MARQUEE = 08; procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin for i := 0 to 100 do begin ProgressBar1.Position := 0; Sleep(50); Application.ProcessMessages; end; end; procedure TForm1.FormCreate(Sender: TObject); begin SetWindowLong(ProgressBar1.Handle, GWL_STYLE, GetWindowLong(ProgressBar1.Handle, GWL_STYLE) or PBS_MARQUEE); end;
#3
Escrito 19 julio 2009 - 07:35
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls; type TForm1 = class(TForm) Button1: TButton; ProgressBar1: TProgressBar; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; const {$EXTERNALSYM PBS_MARQUEE} PBS_MARQUEE = 08; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin SetWindowLong(ProgressBar1.Handle, GWL_STYLE, GetWindowLong(ProgressBar1.Handle, GWL_STYLE) or PBS_MARQUEE); end; procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin for i := 0 to 100 do begin ProgressBar1.Position := 0; Sleep(50); Application.ProcessMessages; end; end; end.
#4
Escrito 20 julio 2009 - 07:46
Author: ceh { Since Comctl32.dll version 6, which is distributed with Windows XP, the ProgressBar Control got a new Style: PBS_MARQUEE. This style lets you display a ProgressBar which moves like a marquee. This means only a part of the small boxes inside move (around five of them) and they are not attached to the left side of the control. This is particularly useful if you need an indeterminate ProgressBar. To use the new Comctl32.dll you'll have to add a Manifest to your project. In Delphi 7 simply drop an XPManifest on the Form, for earlier Versions of Delphi take a look at http://www.swissdelphicenter.ch/de/showcode.php?id=1118 The ProgressBar.Position can then not be set to a particular value anymore. Any arbitrary value will increase the Position by 1, regardless of the values in step, max or min. By reaching the right end of the ProgressBar visualisation begins again at Position 0. }
#5
Escrito 20 julio 2009 - 07:51
{ Delphi's ProgressBar always have a frame. If you wish to place it on a StatusBar it looks not beautifully. You can do small change in the component and you'll get the new one without a frame. } unit NewProgress; // By Vladimir S. <shvetadvipa@mtu-net.ru> interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls; type TNProgressBar = class(TProgressBar) procedure WMNCPAINT(var Msg: TMessage); message WM_NCPAINT; private FShowFrame: boolean; procedure SetShowFrame(Value: boolean); public constructor Create(AOwner: TComponent); override; published property ShowFrame: boolean read FShowFrame write SetShowFrame; end; procedure Register; implementation { TNProgressBar } constructor TNProgressBar.Create(AOwner: TComponent); begin inherited; FShowFrame := True; end; procedure TNProgressBar.SetShowFrame(Value: boolean); begin if FShowFrame <> Value then begin FShowFrame:= Value; RecreateWnd; end; end; procedure TNProgressBar.WMNCPAINT(var Msg: TMessage); var DC: HDC; RC: TRect; begin if ShowFrame then begin inherited; Invalidate; end else begin DC := GetWindowDC(Handle); try Windows.GetClientRect(Handle, RC); with RC do begin Inc(Right, 2); Inc(Bottom, 2); end; Windows.FillRect(DC, RC, Brush.Handle); finally ReleaseDC(Handle, DC); end; end; end; procedure Register; begin RegisterComponents('Controls', [TNProgressBar]); end; end.
#6
Escrito 20 julio 2009 - 07:55
uses commctrl; procedure TForm1.Button1Click(Sender: TObject); begin //Cambia el color a amarillo SendMessage(ProgressBar1.Handle, PBM_SETBARCOLOR, 0, clYellow); end;
#7
Escrito 20 julio 2009 - 11:46
Saludos.
#8
Escrito 20 julio 2009 - 01:51
procedure TForm1.Timer1Timer(Sender: TObject); // Asigna min:= 0 y max:= 10 al progrssbar y 100 al interval del Timer para probar begin if pb.Position < pb.Max then pb.Position := pb.Position +1 else pb.Position := pb.Min; end;
#10
Escrito 25 octubre 2009 - 09:31
Saludos.
#11
Escrito 25 octubre 2009 - 01:10
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls; type TForm1 = class(TForm) ProgressBar1: TProgressBar; Button1: TButton; Button2: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} const PBM_SETMARQUEE = WM_USER + 10; procedure TForm1.FormCreate(Sender: TObject); begin SetWindowLong(ProgressBar1.Handle, GWL_STYLE, GetWindowLong(ProgressBar1.Handle, GWL_STYLE) or PBM_SETMARQUEE); end; procedure TForm1.Button1Click(Sender: TObject); begin ProgressBar1.tag:= 1; while ProgressBar1.tag = 1 do begin Application.ProcessMessages; ProgressBar1.Position:= ProgressBar1.Position+1; if ProgressBar1.Position >= ProgressBar1.Max then ProgressBar1.Position:= 0; Sleep(100); end; end; procedure TForm1.Button2Click(Sender: TObject); begin ProgressBar1.tag:= 0; end; end.
Te subo el ejemplo con fuente y compilado.
Edito para resubir archivo corrupto.
Archivos adjuntos
#12
Escrito 27 octubre 2009 - 06:36
Si el anterior código te servía para diseñar tu movimiento a delante o hacia atrás o de vaivén, este otro, optimizado sólo se mueve hacia delante.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls; type TForm1 = class(TForm) ProgressBar1: TProgressBar; Strat: TButton; Stop: TButton; procedure FormCreate(Sender: TObject); procedure StratClick(Sender: TObject); procedure StopClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} const PBM_SETMARQUEE = WM_USER + 10; procedure TForm1.FormCreate(Sender: TObject); begin SetWindowLong(ProgressBar1.Handle, GWL_STYLE, GetWindowLong(ProgressBar1.Handle, GWL_STYLE) or PBM_SETMARQUEE); end; procedure TForm1.StratClick(Sender: TObject); begin SendMessage (ProgressBar1.Handle, PBM_SETMARQUEE, 1, 100); // Activa 100ms end; procedure TForm1.StopClick(Sender: TObject); begin SendMessage (ProgressBar1.Handle, PBM_SETMARQUEE, 0, 100); // Desactiva end; end.
Saludos.
Edito para resubir archivo corrupto.
Archivos adjuntos
#13
Escrito 27 octubre 2009 - 07:17
Hola Wilson, he probado todos los codes y componente que me facilitaste y todos son un ProgressBar normal, pensé que el constructor PBS_MARQUEE daba un efecto marquesina y pues no es así no hace nada , ando buscando un ProgressBar que se mueva que cuando llegue a la derecha se regrese a la izquierda y así sucesivamente sin fin.
Saludos.
¿Colocaste el componente XPManifest en tu proyecto?
#14
Escrito 28 octubre 2009 - 01:29
¿Colocaste el componente XPManifest en tu proyecto?
Exactamente, en los ejemplos que subo, ambos enlazan el XPManifest, si no o la barra es normal o no se mueve.
Saludos.
#15
Escrito 28 octubre 2009 - 07:10
Saludos.