mathes
asked on
problems with creating a splash-screen
Hi experts,
with the code quoted below I try to create a splash-screen. Unfortunately it does not work as
desired.
The code is syntactically correct, however when I run my program, the splash-screen is not displayed.
Can you please tell me, what I am doing wrong here?
program WinPosh;
uses
Forms,
Dialogs,
SysUtils,
filectrl,
WP_MAINMENUE in 'WP_MAINMENUE.PAS' {frmMainMenu},
WP_Setup in 'WP_SETUP.PAS' {frmWP_Setup},
WP_global_module in 'WP_global_module.pas',
WP_SplashScreen in 'WP_SplashScreen.pas' {frmWP_SplashScreen};
{$R *.RES}
begin
Application.Initialize;
Application.HelpFile := 'WINPOSH.HLP';
Application.CreateForm(Tfr mMainMenu, frmMainMenu);
Application.CreateForm(Tfr mWP_Setup, frmWP_Setup);
Application.CreateForm(Tfr mWP_Splash Screen, frmWP_SplashScreen);
if (FileExists(ExtractFilePat h(Applicat ion.ExeNam e) +
'winposh.ini')=false) then CreateIniFile;
Application.Run
end.
with the code quoted below I try to create a splash-screen. Unfortunately it does not work as
desired.
The code is syntactically correct, however when I run my program, the splash-screen is not displayed.
Can you please tell me, what I am doing wrong here?
program WinPosh;
uses
Forms,
Dialogs,
SysUtils,
filectrl,
WP_MAINMENUE in 'WP_MAINMENUE.PAS' {frmMainMenu},
WP_Setup in 'WP_SETUP.PAS' {frmWP_Setup},
WP_global_module in 'WP_global_module.pas',
WP_SplashScreen in 'WP_SplashScreen.pas' {frmWP_SplashScreen};
{$R *.RES}
begin
Application.Initialize;
Application.HelpFile := 'WINPOSH.HLP';
Application.CreateForm(Tfr
Application.CreateForm(Tfr
Application.CreateForm(Tfr
if (FileExists(ExtractFilePat
'winposh.ini')=false) then CreateIniFile;
Application.Run
end.
OR:
Application.Initialize;
{my suggestion}
Application.CreateForm(Tfr mWP_Splash Screen, frmWP_SplashScreen);
frmWP_SplashScreen.Show;
frmWP_SplashScreen.Update;
{my suggestion}
Application.HelpFile := 'WINPOSH.HLP';
Application.CreateForm(Tfr mMainMenu, frmMainMenu);
Application.CreateForm(Tfr mWP_Setup, frmWP_Setup);
if (FileExists(ExtractFilePat h(Applicat ion.ExeNam e) +
'winposh.ini')=false) then CreateIniFile;
{my suggestion}
frmWP_SplashScreen.Hide;
frmWP_SplashScreen.Free;
{my suggestion}
Application.Run
Application.Initialize;
{my suggestion}
Application.CreateForm(Tfr
frmWP_SplashScreen.Show;
frmWP_SplashScreen.Update;
{my suggestion}
Application.HelpFile := 'WINPOSH.HLP';
Application.CreateForm(Tfr
Application.CreateForm(Tfr
if (FileExists(ExtractFilePat
'winposh.ini')=false) then CreateIniFile;
{my suggestion}
frmWP_SplashScreen.Hide;
frmWP_SplashScreen.Free;
{my suggestion}
Application.Run
And don't forget to add to main form :
procedure TfrmMainMenu.FormCreate(Se nder: TObject);
var
CurrentTime: LongInt;
begin
CurrentTime := GetTickCount div 1500;
while ( (GetTickCount div 1500) < (CurrentTime + 4) ) do
{ nothing };
end;
procedure TfrmMainMenu.FormCreate(Se
var
CurrentTime: LongInt;
begin
CurrentTime := GetTickCount div 1500;
while ( (GetTickCount div 1500) < (CurrentTime + 4) ) do
{ nothing };
end;
ASKER
Dear gnsonic,
I used the following freeware code when I created my own splashscreen:
program Project1;
uses
Forms,
Windows,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {SplashScreen};
{$R *.RES}
begin
SplashScreen := TSplashScreen.Create(Appli cation);
SplashScreen.Show;
Application.Initialize;
SplashScreen.Update;
Sleep(1000); // Or a delay command.
Application.CreateForm(TFo rm1, Form1);
SplashScreen.Hide;
SplashScreen.Free;
Application.Run;
end.
(Source: www.SwissDelphiCenter.ch)
Do you think that this sample code can work?
I used the following freeware code when I created my own splashscreen:
program Project1;
uses
Forms,
Windows,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {SplashScreen};
{$R *.RES}
begin
SplashScreen := TSplashScreen.Create(Appli
SplashScreen.Show;
Application.Initialize;
SplashScreen.Update;
Sleep(1000); // Or a delay command.
Application.CreateForm(TFo
SplashScreen.Hide;
SplashScreen.Free;
Application.Run;
end.
(Source: www.SwissDelphiCenter.ch)
Do you think that this sample code can work?
i use this in one of my projects
program BP;
uses
Forms,
BP_u1 in 'BP_u1.pas' {Form1},
BP_u3 in 'BP_u3.pas' {F_AG: TFrame},
BP_u2 in 'BP_u2.pas' {F_PResource: TFrame},
fr_prg_u in 'fr_prg_u.pas' {fr_prg: TFrame},
fr_pr_u in 'fr_pr_u.pas' {fr_pr: TFrame},
fr_prc_u in 'fr_prc_u.pas' {fr_prcal: TFrame},
fr_agg_u in 'fr_agg_u.pas' {fr_agg: TFrame},
fr_ag_u in 'fr_ag_u.pas' {fr_ag: TFrame},
fr_fp_u in 'fr_fp_u.pas' {fr_agl: TFrame},
fr_fpg_u in 'fr_fpg_u.pas' {fr_aglg: TFrame},
BP_u4 in 'BP_u4.pas' {F_FP: TFrame},
bp_progress_u in 'bp_progress_u.pas' {frmProgress},
bp_Splash_u in 'bp_Splash_u.pas' {f_Splash},
fr_ppl_u in 'fr_ppl_u.pas' {fr_ppl: TFrame},
f_ppo_u in 'f_ppo_u.pas' {fr_ppo: TFrame},
repBeleg1 in 'repBeleg1.pas' {qr_Beleg1: TQuickRep},
repBeleg2 in 'repBeleg2.pas' {qrBeleg2: TQuickRep},
uRepBBPO in 'uRepBBPO.pas' {RepBBPO: TQuickRep};
{$R *.RES}
begin
Application.Initialize;
f_Splash := tf_Splash.Create(Applicati on);
f_Splash.Show;
f_Splash.BringToFront;
Application.ProcessMessage s;
try
Application.HelpFile := 'DruckAuftragHilfe.hlp';
Application.Title := 'Vistaworks PPS';
Application.CreateForm(TFo rm1, Form1);
Application.CreateForm(TRe pBBPO, RepBBPO);
except
Raise;
Application.Terminate;
end;
f_Splash.Release;
Application.Run;
end.
meikl ;-)
program BP;
uses
Forms,
BP_u1 in 'BP_u1.pas' {Form1},
BP_u3 in 'BP_u3.pas' {F_AG: TFrame},
BP_u2 in 'BP_u2.pas' {F_PResource: TFrame},
fr_prg_u in 'fr_prg_u.pas' {fr_prg: TFrame},
fr_pr_u in 'fr_pr_u.pas' {fr_pr: TFrame},
fr_prc_u in 'fr_prc_u.pas' {fr_prcal: TFrame},
fr_agg_u in 'fr_agg_u.pas' {fr_agg: TFrame},
fr_ag_u in 'fr_ag_u.pas' {fr_ag: TFrame},
fr_fp_u in 'fr_fp_u.pas' {fr_agl: TFrame},
fr_fpg_u in 'fr_fpg_u.pas' {fr_aglg: TFrame},
BP_u4 in 'BP_u4.pas' {F_FP: TFrame},
bp_progress_u in 'bp_progress_u.pas' {frmProgress},
bp_Splash_u in 'bp_Splash_u.pas' {f_Splash},
fr_ppl_u in 'fr_ppl_u.pas' {fr_ppl: TFrame},
f_ppo_u in 'f_ppo_u.pas' {fr_ppo: TFrame},
repBeleg1 in 'repBeleg1.pas' {qr_Beleg1: TQuickRep},
repBeleg2 in 'repBeleg2.pas' {qrBeleg2: TQuickRep},
uRepBBPO in 'uRepBBPO.pas' {RepBBPO: TQuickRep};
{$R *.RES}
begin
Application.Initialize;
f_Splash := tf_Splash.Create(Applicati
f_Splash.Show;
f_Splash.BringToFront;
Application.ProcessMessage
try
Application.HelpFile := 'DruckAuftragHilfe.hlp';
Application.Title := 'Vistaworks PPS';
Application.CreateForm(TFo
Application.CreateForm(TRe
except
Raise;
Application.Terminate;
end;
f_Splash.Release;
Application.Run;
end.
meikl ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That is my version:
Application.Initialize;
SplashScreen := TSplashScreen.Create(Appli cation);
SplashScreen.Show;
SplashScreen.Refresh;
Application.CreateForm(TMa inForm, MainForm);
Application.Run;
and the splash screen form:
unit Splash;
interface
uses
Windows, Forms, Graphics, Controls, Classes, ExtCtrls, jpeg, StdCtrls;
type
TSplashScreen = class(TForm)
Timer1: TTimer;
Image1: TImage;
procedure Timer1Timer(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
public
end;
var
SplashScreen: TSplashScreen;
SplashExists: Boolean = False;
implementation
{$R *.DFM}
uses
JCLGraphics;
procedure TSplashScreen.Timer1Timer( Sender: TObject);
begin
Close;
end;
procedure TSplashScreen.Image1Click( Sender: TObject);
begin
Timer1.Free;
Close;
end;
procedure TSplashScreen.FormCreate(S ender: TObject);
var
HRegion: HRGN;
begin
SplashExists := True;
// from Jedi Code Library
HRegion := CreateRegionFromBitmap(Ima ge1.Pictur e.Bitmap, $FFFFFF, rmExclude);
SetWindowRgn(Handle, HRegion, False);
end;
procedure TSplashScreen.FormDestroy( Sender: TObject);
begin
SplashExists := False;
end;
end.
The refinement is that the splash screen destroys itself by a timer without slowin down app start.
It also closes on click which is something i want for all splash screens.
Application.Initialize;
SplashScreen := TSplashScreen.Create(Appli
SplashScreen.Show;
SplashScreen.Refresh;
Application.CreateForm(TMa
Application.Run;
and the splash screen form:
unit Splash;
interface
uses
Windows, Forms, Graphics, Controls, Classes, ExtCtrls, jpeg, StdCtrls;
type
TSplashScreen = class(TForm)
Timer1: TTimer;
Image1: TImage;
procedure Timer1Timer(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
public
end;
var
SplashScreen: TSplashScreen;
SplashExists: Boolean = False;
implementation
{$R *.DFM}
uses
JCLGraphics;
procedure TSplashScreen.Timer1Timer(
begin
Close;
end;
procedure TSplashScreen.Image1Click(
begin
Timer1.Free;
Close;
end;
procedure TSplashScreen.FormCreate(S
var
HRegion: HRGN;
begin
SplashExists := True;
// from Jedi Code Library
HRegion := CreateRegionFromBitmap(Ima
SetWindowRgn(Handle, HRegion, False);
end;
procedure TSplashScreen.FormDestroy(
begin
SplashExists := False;
end;
end.
The refinement is that the splash screen destroys itself by a timer without slowin down app start.
It also closes on click which is something i want for all splash screens.
ASKER
Hi experts,
thank you all for your feedback. I found out that all your suggestions work well in my demo sources.
Meikl: I would like to reward you with points, too.
Please post a dummy comment to my other question, and I will give you points, too.
ASKER
Dear Robert,
your solution works very well too. I will ask a question especially to you. Pl4ease post a dummy comment and I will reward you with points, too.
your solution works very well too. I will ask a question especially to you. Pl4ease post a dummy comment and I will reward you with points, too.
procedure TfrmWP_SplashScreen.FormSh
begin
SetWindowPos(Handle,HWND_T
end;