On versions of Windows later then Win95, you can subclass an edit control to
intercept the WM_CTLCOLOREDIT message (for TEdit, it would be
CN_CTLCOLOREDIT instead) and return a brush that is created from a bitmap.
You can then draw a bitmap of whatever type of progress display you want.
Here is a simple example:
TForm1 = class(TForm)
published
Edit1: TEdit;
Timer1: TTimer;
procedure FormCreate(Sender: TObject)
procedure Timer1Timer(Sender: TObject);
private
OldWndProc: TWndMethod;
procedure EditWndProc(var Message: TMessage);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
OldWndProc := Edit1.WindowProc;
Edit1.WindowProc := EditWndProc;
end;
procedure TForm1.EditWndProc(var Message: TMessage);
var
bmp: TBitmap;
r: TRect;
oldRight: Integer;
begin
if Message.Msg = CN_CTLCOLOREDIT then
begin
Windows.SetTextColor(Message.WParam,
ColorToRGB(Edit1.Font.Color));
Window.SetBkMode(Message.WParam, TRANSPARENT);
bmp := TBitmap.Create;
try
r := Edit1.ClientRect;
bmp.Width := (r.Right - r.Left);
bmp.Height := (r.Bottom - r.Top);
if Edit1.Tag > 0 then
begin
oldRight := r.Right;
r.Right := r.Left + ((r.Right - r.Left) *
(Extended(Edit1->Tag) / 100);
bmp.Canvas.Brush.Color := clAqua;
bmp.Canvas.FillRect(r);
r.Left := r.Right;
r.Right := oldRight;
end;
bmp.Canvas.Brush.Color := Edit1.Color;
bmp.Canvas.FillRect(r);
Message.Result := Windows.CreatePatternBrush(bmp.Handle);
finally
bmp.Free;
end;
Exit;
end;
OldWndProc(Message);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
// I set Timer1.Interval to 50ms...
if Edit1.Tag >= 100 then
Edit1.Tag := 0
else
Edit1.Tag := Edit1.Tag + 1;
Edit1.Invalidate;
end;