Solved

problems with creating a splash-screen

Posted on 2002-04-27
9
246 Views
Last Modified: 2010-04-04
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(TfrmMainMenu, frmMainMenu);
  Application.CreateForm(TfrmWP_Setup, frmWP_Setup);
  Application.CreateForm(TfrmWP_SplashScreen, frmWP_SplashScreen);
  if (FileExists(ExtractFilePath(Application.ExeName) +
     'winposh.ini')=false) then  CreateIniFile;
  Application.Run
end.  

0
Comment
Question by:mathes
9 Comments
 
LVL 9

Expert Comment

by:ginsonic
ID: 6974569
I think that you must add to splash form something alike:



procedure TfrmWP_SplashScreen.FormShow(Sender: TObject);
begin
  SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
end;
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6974572
OR:

Application.Initialize;
{my suggestion}
Application.CreateForm(TfrmWP_SplashScreen, frmWP_SplashScreen);
frmWP_SplashScreen.Show;
frmWP_SplashScreen.Update;
{my suggestion}
Application.HelpFile := 'WINPOSH.HLP';
Application.CreateForm(TfrmMainMenu, frmMainMenu);
Application.CreateForm(TfrmWP_Setup, frmWP_Setup);
if (FileExists(ExtractFilePath(Application.ExeName) +
    'winposh.ini')=false) then  CreateIniFile;
{my suggestion}
frmWP_SplashScreen.Hide;
frmWP_SplashScreen.Free;
{my suggestion}
Application.Run


0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6974575
And don't forget to add to main form :

procedure TfrmMainMenu.FormCreate(Sender: TObject);
var
  CurrentTime: LongInt;
begin
  CurrentTime := GetTickCount div 1500;
  while ( (GetTickCount div 1500) < (CurrentTime + 4) ) do
    { nothing };
end;
0
 

Author Comment

by:mathes
ID: 6974602
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(Application);
  SplashScreen.Show;
  Application.Initialize;
  SplashScreen.Update;
  Sleep(1000); // Or a delay command.
  Application.CreateForm(TForm1, Form1);
  SplashScreen.Hide;
  SplashScreen.Free;
  Application.Run;
end.

(Source: www.SwissDelphiCenter.ch)

Do you think that this sample code can work?


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6974612
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(Application);
  f_Splash.Show;
  f_Splash.BringToFront;
  Application.ProcessMessages;
  try
    Application.HelpFile := 'DruckAuftragHilfe.hlp';
    Application.Title := 'Vistaworks PPS';
    Application.CreateForm(TForm1, Form1);
    Application.CreateForm(TRepBBPO, RepBBPO);
  except
    Raise;
    Application.Terminate;
  end;
  f_Splash.Release;
  Application.Run;
end.

meikl ;-)
0
 
LVL 9

Accepted Solution

by:
ginsonic earned 100 total points
ID: 6974617
I think that Application.Initialize most be first .
Tested my code and work for me .
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6974706
That is my version:
  Application.Initialize;
  SplashScreen := TSplashScreen.Create(Application);
  SplashScreen.Show;
  SplashScreen.Refresh;
  Application.CreateForm(TMainForm, 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(Sender: TObject);
var
 HRegion: HRGN;
begin
  SplashExists := True;
  // from Jedi Code Library
  HRegion := CreateRegionFromBitmap(Image1.Picture.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.

0
 

Author Comment

by:mathes
ID: 6974736

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.
0
 

Author Comment

by:mathes
ID: 6974740
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now