1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
unit SplashForm;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
GIFImg,
Vcl.Dialogs,
Vcl.ExtCtrls;
type
TMyFormSplashThread = class(TThread)
protected
procedure Execute; override;
public
constructor Create(CreateSuspended: Boolean);
procedure DoTerminate; override;
end;
TFormSplash = class(TForm)
ConteneurTImage: TImage;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
procedure Execute;
end;
var
FormSplash: TFormSplash;
MyFormSplashThread: TMyFormSplashThread;
implementation
{$R *.dfm}
{ MyThread }
constructor TMyFormSplashThread.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
// Détruire à la sortie
FreeOnTerminate := True;
// Détermination de la priorité du thread
Priority := tpHighest;
FormSplash := TFormSplash.Create(Application);
// Si le thread est en attente, le démarrer
if CreateSuspended then
Resume;
end;
procedure TMyFormSplashThread.DoTerminate;
begin
if Assigned(FormSplash) then begin
FormSplash.CloseModal;
FormSplash.Release;
FormSplash.Free;
end;
inherited;
end;
procedure TMyFormSplashThread.Execute;
begin
FormSplash.Execute;
//Boucler tant que l'utilisateur n'a pas demandé de stopper
while not Terminated do begin
Synchronize(Application.ProcessMessages);
// Synchronize(FormSplash.Refresh);
end;
end;
{ TFormSplash }
procedure TFormSplash.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TFormSplash.Execute;
var
FullForm, Spinner: HRGN; // Declaration des HRGN
ImageGIF: TGIFImage;
begin
FullForm := CreateRectRgn(0, 0, width, height); // R1 englobe toute la form
Spinner := CreateEllipticRgn(10, 10, 210, 210); // l'exterieur du spinner
CombineRgn(FullForm, FullForm, Spinner, RGN_AND);
DeleteObject(Spinner);
Spinner := CreateEllipticRgn(33, 33, 190, 190); // l'interieur du spinner
CombineRgn(FullForm, FullForm, Spinner, RGN_XOR);
DeleteObject(Spinner);
SetWindowRgn(handle, FullForm, true); // Applique le tout à la form
// je charge mon image animée GIF
ImageGIF := TGIFImage.Create;
ImageGIF.Animate := true;
ImageGIF.LoadFromFile('Spinner220.gif');
ConteneurTImage.Picture.Assign(ImageGIF);
// et j'affiche ma form
ShowModal;
Refresh;
end;
end. |
Partager