Solved

problems with creating a splash-screen

Posted on 2002-04-27
9
245 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

20 Experts available now in Live!

Get 1:1 Help Now