Need to loading GIF images in your application, to show the progress of the program, but in the main thread initialization is very resource-intensive, cause if it is in the main thread loading GIF, won't refresh,
Then try the child thread by thread load of every frame image, in order to realize the dynamic effect, but caused frequently applied to the main thread for resources, caused the initialization program more slowly,
The HTML code is as follows, you have any other ideas?
The unit TRBProcessing;
Interface
USES the
Winapi. Windows, Winapi Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics,
The Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Vcl. ExtCtrls, Vcl. ImgList, Vcl. StdCtrls, Vcl. Imaging. GIFImg;
Type
TRunImage=class (TThread)
Private
FBox: TPaintBox;
FImageList: TImageList;
FStep: Integer;
FisSetTransparentColor: Boolean;
Protected
Procedure the Execute; Override.
Public
The constructor Create (ABox: TPaintBox; AImageList: TImageList);
The property isSetTransparentColor: Boolean read FisSetTransparentColor write FisSetTransparentColor;
end;
Type
TTRBFrmProcessing=class (TForm)
ImgRun: TImageList;
ImgDog: TPaintBox;
Procedure FormClose (Sender: TObject; Var Action: TCloseAction);
Procedure FormShow (Sender: TObject);
Private
ORunImage: TRunImage;
{Private declarations}
Protected
Public
{Public declarations}
end;
Var
TRBFrmProcessing: TTRBFrmProcessing;
Procedure ProcessingWaitMsg2 (AFlag: Integer; AMsg: string=");
Const
IsProcMsgShow: Integer=1;
IsProcMsgHide: Integer=0;
IsFormTransparentColor: Integer=2;
IsFormNoTransparentColor: Integer=3;
Implementation
{$R *. DFM}
Procedure ProcessingWaitMsg2 (AFlag: Integer; AMsg: string=");
The begin
If AFlag=isProcMsgHide then
The begin
If Application. FindComponent (' TRBFrmProcessing) & lt;> Nil then
The begin
TRBFrmProcessing. TransparentColor:=True;
Sleep (100);
TRBFrmProcessing. Refresh;
TRBFrmProcessing. Hide;
TRBFrmProcessing. Close;
FreeAndNil (TRBFrmProcessing);
end;
The Exit;
End
Else if AFlag=isFormTransparentColor then
The begin
If Application. FindComponent (' TRBFrmProcessing) & lt;> Nil then
The begin
TRBFrmProcessing. TransparentColor:=True;
TRBFrmProcessing. ORunImage. Suspended:=True;
TRBFrmProcessing. ORunImage. IsSetTransparentColor:=True;
TRBFrmProcessing. ORunImage. Resume;
end;
End
Else if AFlag=isFormNoTransparentColor then
The begin
If Application. FindComponent (' TRBFrmProcessing) & lt;> Nil then
The begin
TRBFrmProcessing. TransparentColor:=False;
end;
End
The else
The begin
If Application. FindComponent (' TRBFrmProcessing ')=nil then
The begin
TRBFrmProcessing:=TTRBFrmProcessing. Create (Application);
end;
TRBFrmProcessing. TransparentColor:=True;
TRBFrmProcessing. TransparentColorValue:=clBtnFace;
With TRBFrmProcessing do
The begin
The Show;
The Update;
end;
end;
end;
{TRunDog}
The constructor TRunImage. Create (ABox: TPaintBox; AImageList: TImageList);
The begin
FBox:=ABox;
FImageList:=AImageList;
FStep:=0;
FreeOnTerminate:=True;
FisSetTransparentColor:=False;
Inherited the Create (False);
end;
Procedure TRunImage. Execute;
Var
OIcon: TIcon;
OBitMap: TBitmap;
The begin
OIcon:=TIcon. Create;
OBitMap:=TBitmap. Create;
Try
Repeat
//if FisSetTransparentColor then
//TRBFrmProcessing_Two. TransparentColor:=True
//else
//TRBFrmProcessing_Two. TransparentColor:=False;
The Lock; FBox. Canvas.
FImageList. GetIcon (FStep oIcon);
//FBox. Canvas. Brush. Color:=TPanel (FBox. The Parent). Color;//clBtnFace;
FBox. Canvas. FillRect (FBox. Canvas. ClipRect);
FBox. Canvas. The Draw (0, 0, oIcon);
FBox. Canvas. Unlock;
Application. ProcessMessages;
Sleep (50);
FStep:=FStep + 1;
If FStep & gt; 45 then
The begin
Sleep (100);
FStep:=0;
end;
Until Terminated;
The finally
OIcon. Free;
OBitMap. Free;
end;
end;
Procedure TTRBFrmProcessing. FormClose (Sender: TObject;
Var Action: TCloseAction);
The begin
ORunImage. The Terminate;
Sleep (20);
TRBFrmProcessing. TransparentColor:=True;
TRBFrmProcessing. Color:=clBlack;
end;
Procedure TTRBFrmProcessing. FormShow (Sender: TObject);
The begin
ORunImage:=TRunImage. Create (ImgDog ImgRun);
ImgDog. Left:=Self. Left;
ImgDog. Top:=the self. The Top;
Self. Width:=ImgDog. Width;
Self. Height:=ImgDog. Height;
end;
End.
DFM
The object TRBFrmProcessing: TTRBFrmProcessing
Left=0
Top=0
BorderStyle=bsNone
Caption='TRBFrmProcessing'
ClientHeight=166
ClientWidth=168
Color=clBtnFace
TransparentColor=True
TransparentColorValue=https://bbs.csdn.net/topics/clBtnFace
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull