-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSplashForm.pas
134 lines (112 loc) · 3.36 KB
/
SplashForm.pas
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
132
133
134
unit SplashForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,
SimpleTimer,
InflatablesList_Manager;
type
TfSplashForm = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
fILManager: TILManager;
fSplashBitmap: TBitmap;
fSplashPosition: TPoint;
fSplashSize: TSize;
fSplashBlendFunction: TBlendFunction;
fCloseTimer: TSimpleTimer;
protected
procedure OnCloseTimerHandler(Sender: TObject);
public
{ Public declarations }
procedure Initialize(ILManager: TILManager);
procedure Finalize;
procedure ShowSplash;
procedure LoadingDone(Success: Boolean);
end;
var
fSplashForm: TfSplashForm;
implementation
uses
StrRect,
MainForm;
{$R *.dfm}
// resource containing the splash bitmap
{$R '..\resources\splash.res'}
procedure TfSplashForm.OnCloseTimerHandler(Sender: TObject);
begin
Close;
end;
//==============================================================================
procedure TfSplashForm.Initialize(ILManager: TILManager);
begin
fILManager := ILManager;
end;
//------------------------------------------------------------------------------
procedure TfSplashForm.Finalize;
begin
// nothing to do
end;
//------------------------------------------------------------------------------
procedure TfSplashForm.ShowSplash;
begin
Show;
end;
//------------------------------------------------------------------------------
procedure TfSplashForm.LoadingDone(Success: Boolean);
begin
If Success then
begin
fMainForm.Show;
fCloseTimer.Enabled := True;
// closing in this case is called by timer
end
else Close;
end;
//==============================================================================
procedure TfSplashForm.FormCreate(Sender: TObject);
var
ResStream: TResourceStream;
begin
// this all must be here, because the window is shown before a call to initialize
// get splash bitmap
ResStream := TResourceStream.Create(hInstance,StrToRTL('splash'),PChar(10){RT_RCDATA});
try
ResStream.Seek(0,soBeginning);
fSplashBitmap := TBitmap.Create;
fSplashBitmap.LoadFromStream(ResStream);
finally
ResStream.Free;
end;
// fill some required info
fSplashPosition := Point(0,0);
fSplashSize.cx := fSplashBitmap.Width;
fSplashSize.cy := fSplashBitmap.Height;
fSplashBlendFunction.BlendOp := AC_SRC_OVER;
fSplashBlendFunction.BlendFlags := 0;
fSplashBlendFunction.SourceConstantAlpha := 255;
fSplashBlendFunction.AlphaFormat := AC_SRC_ALPHA;
// adjust window style, size and position
BorderStyle := bsNone;
FormStyle := fsStayOnTop;
ClientWidth := fSplashBitmap.Width;
ClientHeight := fSplashBitmap.Height;
Position := poScreenCenter;
// layered window calls (low-level)
SetWindowLong(Handle,GWL_EXSTYLE,GetWindowLong(Handle,GWL_EXSTYLE) or WS_EX_LAYERED);
UpdateLayeredWindow(Handle,0,nil,@fSplashSize,fSplashBitmap.Canvas.Handle,@fSplashPosition,0,@fSplashBlendFunction,ULW_ALPHA);
// some other stuff
fCloseTimer := TSimpleTimer.Create;
fCloseTimer.Enabled := False;
fCloseTimer.Interval := 500; // 0.5s
fCloseTimer.OnTimer := OnCloseTimerHandler;
end;
//------------------------------------------------------------------------------
procedure TfSplashForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(fCloseTimer);
FreeAndNil(fSplashBitmap);
end;
end.