Mega Code Archive

 
Categories / Delphi / Examples
 

Splashscreen

HOW TO SET UP A 'SPLASH' SCREEN ie a sexy graphical form to display while a program loads 1. First do stuff in the PROJECT source file as follows: note that here the form called 'startup' is the main form but that here we also want the LOGIN form (which could just as easily be a splash form) to show BEFORE the main form. What's important is the way we create it up immediately after Application.Initialise. Note also the syntax for creating this form. 2. Use SHOW to Show the form. here we use showmodal 'cus it's a login form but Show will keep the form open for as long as program execution assicated with form is going on. So for a splash form in the FormCreate precedure we should then call up the code to DO THE LOADING. program Fox; {Richard Ebbs for Honeywood...} {October 1999...} uses Forms, StartUp in 'StartUp.pas' {MainForm}, Login in 'Login.pas' {LoginForm}, {$R *.RES} begin Application.Initialize; LoginForm := TLoginForm.Create(Application); LoginForm.ShowModal; Application.CreateForm(TMainForm, MainForm); Application.Run; end. 3. The QUICK way to put a graphic image on this form is to place a TImage component on the form (sized to the dimensions of a preprepared graphical image) and at design time use the object inspector to load a graphic into the TImage. (We could of course load an image at runtime also). If we use a .bmp bitmap file where we've cut around an image and pasted it to a new file in PaintShop Pro, for instance, then by setting the TImage's 'transparent' property to True we get a transparent surround to the image. *************************************************************************** Hopefully this much code isn't a problem, but in this case I think it's warranted. Here's some code I use for mine. I have it set for a five second delay, and here is the main application code: try SplashScreen := TSplashScreen.Create(Application); SplashScreen.Show; SplashScreen.Update; Application.Initialize; Application.Title := 'MyApp'; Application.HelpFile := 'MyApp.hlp'; Application.CreateForm(TMainForm, MainForm); repeat Application.ProcessMessages; until SplashScreen.CloseQuery; SplashScreen.Close; finally SplashScreen.Free; end; I have a separate unit for the Splash screen, that contains only a TTimer and a TImage: unit Splash; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls; type TSplashScreen = class(TForm) Image1: TImage; Timer1: TTimer; procedure Timer1Timer(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); private { Private declarations } public { Public declarations } end; var SplashScreen: TSplashScreen; implementation {$R *.DFM} procedure TSplashScreen.Timer1Timer(Sender: TObject); begin Timer1.Enabled := FALSE; end; procedure TSplashScreen.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose := not Timer1.Enabled; end; end. Set the timer interval up for the "expiration" amount of time, and enable it. When the timer fires, the timer will automatically disable. The splash will not close down until the timer expires (set to disabled) ... It's pretty simple, but it works well for me. Hope this helps, Bob -----Original Message----- From: delphi-admin@elists.org [mailto:delphi-admin@elists.org]On Behalf Of Helen ap Derwen Yewlett Sent: Saturday, October 14, 2000 5:50 PM To: delphi@elists.org Subject: Re:Splash screens Didn't actually know what a splash screen was, so went walk about on the net and found a very good tutorial http://www.innotts.co.uk/~zephyr/splash.html Anyway I followed the instructions and hey presto .. it works.. except that the program I attached it to, loads so fast you never actually see the splash screen. It just flashes past your eyes. Looked for a delay routine that I could stick in before the application.run statement but couldn't find one and the help wasn't a help either! Since I've only programmed the splash screen to demonstrate to the kids I teach the idea, I'd really like a delay line please. Many thanks Helen :-) **************************************************************************************** Hello! The following code should do the trick Just create a new form to use as your splash screen. Make sure that it is not an auto-create form, i.e. If you call your form TitleForm, as I have done, go to the source file of the application (Project -> View Source) and remove the line that says Application.CreateForm(TTitleForm,TitleForm). Then change the source of your project as below. BEGIN WITH TTitleForm.Create (NIL) DO TRY Screen.Cursor:=crHourGlass; Show; //Show the title screen Update; //Update the splash screen Application.Title:='TITLE OF YOUR APPLICATION'; //Do any processing here, eg creating any static forms //Or put some sort of delay Screen.Cursor:=CrDefault; FINALLY Free; // Free the splash screen END; Application.Run; END; **************************************************************************************** Hi fellaz, recently I had a problem with colorfull cursor with more than 16 colors. Here is the solution that I use. The idea is very simple. To use a animated cursor (ANI) but with one frame. :) I suggest Axialis Cursor, maybe Microangelo or some similar drawing tool to create a 32x32x65K cursor (supported by Axialis). Copy & paste any bitmap in the cursor layer and use the following code: procedure TForm1.Button1Click(Sender: TObject); var h : THandle; begin h := LoadImage(0, 'C:\TheWall\Magic.ani', IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE or LR_LOADFROMFILE); if h = 0 then ShowMessage('Cursor not loaded') else begin Screen.Cursors[1] := h; Form1.Cursor := 1; end; end; I find this code on Borland's site. You can also insert ANI file into EXE. This is also documented ont the site. Regards, Kliment Andreev ***************************************************************************************** > Any one know of a freeware tool for making splash screens > > or some code that I could use to make a splash screen for an > application?? > What we do is create a new form, and remove it from the auto-create list of the project. We add the picture and everything else went and want and set it to border-style bsNone. Then, we go in to the project source. (Project|View Source) In there, declare a variable of the type of your splashscreen form. After the Application.Initialize, but before any of the form creates, create your form manually, then .Show it. After all of the forms are created, .Hide it and .Free it. It's not the optimal solution, but it's certainly easy to code. Todd Lang