Pageranking on Google! Check PageRank

Page Last Edited 03/8/12 12:51

Easy Splashscreen Writing Guide by Nullified

Website

See also: New - Create a fully featured webbrowser

download easy splashscreen writing guide finished

How to create your own splashscreen in less than 2 minutes! A splashscreen is mostly a timage [ in delphi programming language ] which appears when a program is loading, a sort of graphical enhancement. You could also use it for a description ofcourse, with text in it that warns or informs the user of the copyright or terms of use maybe. They can cover the entire screen but mostly they cover only a smaller part of the desktop. 16 bit applications that natively use the full screen will ofcourse always, without exception, use the full screen as well. It is always good practise to give the user the ability to disable the splash from appearing when he or she restarts your application, at least in my opinion. Some screens are really awesome and do not take ages to load while others, which maybe display only some user rights or whatever, are not that cool at all and those I would want to disable myself. Imagine it splashing around for half an hour, ofcourse I am a little bit exaggerating but you get the point

To view the popups, and this counts for any win32 hlp file you would want to see, I have included the microsoft windows updates for windows 7


Quick Start

This is a basic and very short demonstration for creating your own delphi splashscreen in less than 3 minutes. Following this tutorial, you will learn to create this appealing enhancement, that can be disabled by un checking a check box on the mainform, it makes use of an Inifile to store the value and enable and disable the appearance of the splashscreen. About the included example, to test it a simple restart button was added to it, in order to make that work Shellapi was added to the uses clausule of Form1.




1. Create a new project


2. Add another form to it [menu File= New= Form]


3. To the uses clausule of Form1 add: Inifiles
...
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, IniFiles;

...


4. To the private section of Form1 add: Inifile : Tinifile;
...
private
    IniFile: TIniFile;

...


5. Add the Unit2 to the uses clausule of Form1 just below Implementation
...
implementation
uses
  Unit2;
{$R *.dfm}

...


6. Drop a check box on Form1 [Checkbox1], and a label [Label1], set the Label its caption property to: ShowSplash [or any Variable name, that you prefer to use as indicator that the check box serves for enabling and/or disabling the splashscreen]


7. Double click Form1 and change the OnFormCreate event as below:
...
procedure TForm1.FormCreate(Sender: TObject);
var
   Splash: Boolean;

begin
Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));
with Inifile do
  try
    Splash:= ReadBool('ShowSplash','LastChoice', True );
    Checkbox1.Checked := Splash;
   if Splash then
   begin
     Sleep(1000); //This is the time you want the splash to show in miliseconds
     Form2.Close;
     Form2.Release;

   end;
  finally
    Free;
end;

end;

...


8. Create the OnFormClose event on Form1 and change it to the following:
...
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
   Splash: Boolean;

begin
  Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));
  Splash := Checkbox1.Checked;
  with Inifile do
  try
   WriteBool('ShowSplash','LastChoice', Splash);
  finally
   Free;
  end;

end;

...


9. Open Form2, add Inifiles to the uses clausule  of Form2:
...
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, IniFiles;

...


10. Declare the boolean and the Tinifile just below the var section, after the Form2 declaration:

...
var
  Form2: TForm2;
  Splash: Boolean;
  Inifile: TIniFile;


implementation
{$R *.dfm}

...


11. Below the inclusion of the Delphi Form [{$R *.dfm}], in Form2 add the following code in green

...
implementation
{$R *.dfm}

initialization
Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));
  with Inifile do
    try
      Splash:= ReadBool('ShowSplash','LastChoice', True);
     finally
      Free;
    end;
    if Splash then
      begin
        Form2 := TForm2.Create(nil);
        Form2.Show;
        Form2.Update;

      end;
end.

 ...

12. Change the border style of Form2 to bsNone in the object inspector

Done!

Notes


Of course a splashscreen that has the default color and is empty, is not really cool so add an image to it, or anything you want to appear there, see the included example for a simple basic idea, but technically speaking you are finished and have just created your own splashscreen, and you no longer have to rely on 3rd party components, as I have said before and will keep saying!

splashscreen writing guide example

 

Naming conventions


Note that variables can be called anything you wish [except for keywords etc], it is good practice to name them to something useful, so the name of it already tells you at least a bit what is it about. Then if you are finished with your project you can always do a search and place to make the variables shorter [saving a bit of space] and making them more difficult to guess, should you wanna'. Also, it is a good thing to name the components, and the forms, and units to something meaningful. The advantage of properly named forms, are so you can tell them apart from the standard forms with names given to them by delphi itself, and they wont be written over accidentally easy, plus it is easier to work with them in a single project that has more forms. However, for ease of use of this tutorial, I used the standard names.

Also, for your own sake [readability] it is best to name your forms like something more clear. In this tutorial however, I used the standard names Delphi gives them, to not make it more complex and lengthy. My own screen would be named something like: SplashForm, while Form1 would be named: MainForm. Same goes for components, Checkbox1 does not say anything what it is used for or what it is about, I myself would name it something like: chkSplash.  


Position


The position can and maybe should be altered too, but this is purely personal, so I did not discuss that. In the included example, position of Form1 was set to poDesktopCenter, and position of Form2 was set to poMainformCenter, so the splash appears centered in where the Form1 will appear.

The finished forms are below for viewing, go to downloads to download all tutorials with included demo's, dfm, pas and dpr files:

===============================================================
Unit1.pas
================================================================

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, IniFiles;

type
  TForm1 = class(TForm)
    Checkbox1: TCheckBox;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);

  private
    IniFile: TIniFile;

  public
    { Public declarations }
  end;
var
  Form1: TForm1;

implementation

uses
  Unit2;


{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
   Splash: Boolean;
begin
Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));

with Inifile do
  try
    Splash:= ReadBool('ShowSplash','LastChoice', True );
    Checkbox1.Checked := Splash;
   if Splash then
   begin
     Sleep(1000);
     Form2.Close;
     Form2.Release;
   end;
  finally
    Free;
end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
   Splash: Boolean;
begin
  Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));
  Splash := Checkbox1.Checked;
  with Inifile do
     try
       WriteBool('ShowSplash','LastChoice', Splash);
     finally
   Free;
  end;
end;
end.

================================================================


================================================================
Unit2.pas [Your splashscreen]
================================================================

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, IniFiles;

type
  TForm2 = class(TForm)
  private
  public
  end;

var
  Form2: TForm2;
  Splash: Boolean;
  Inifile: TIniFile;

implementation
{$R *.dfm}

initialization
Inifile := TIniFile.Create(Changefileext(application.exename, '.ini'));
  with Inifile do
    try
      Splash:= ReadBool('ShowSplash','LastChoice', True);
     finally
      Free;
    end;
    if Splash then
      begin
        Form2 := TForm2.Create(nil);
        Form2.Show;
        Form2.Update;
      end;
end.

================================================================
End of Writing Guide
================================================================

Shapes and transparency


Shapes and transparency is a follow up on eswg and involves transparency to get even more cool effects while using a splashscreen, you can use the source files of eswg and then continue to Create your own delphi splashscreen with transparancy or first follow this one and use the files you created yourself but in any case it is advised to read on to the bottom.


You can get really cool results if you add an image that has a non rectangular shape, see the below pictures.

splashscreen writing guide exampleexample writing guide with transparencyanother sample for writing guide  using transparency

Note that in order to make use of transparency you can add extra units to delphi like gif or png components, however since pngimage has some sort of trouble because of it being used for commercial purposes, I will not offer it for download here, but I will do that on the following page, go to download Pngcomponents courtesy Martijn Saly to obtain it.

If you want to read how to create partially transparent splashses then read on and click the above link which sends you to eswgv2, which is a minute of your time extra

See also:


================================================================

Everything by Nullified can be downloaded together with demo files at my site for free for always