home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / zkuste / delphi / kompon / d3456 / PICSHOW.ZIP / DBDemo / Splash.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2000-09-04  |  2.5 KB  |  80 lines

  1. unit Splash;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   PicShow, ExtCtrls;
  8.  
  9. type
  10.   TSplashForm = class(TForm)
  11.     PicShow: TPicShow;
  12.   private
  13.     procedure Initialize;
  14.   public
  15.     class function Execute: TSplashForm;
  16.   end;
  17.  
  18. implementation
  19.  
  20. {$R *.DFM}
  21.  
  22. procedure TSplashForm.Initialize;
  23. var
  24.   Background: TBitmap;
  25.   DC: HDC;
  26. begin
  27.   // First we set position of the form on the center of desktop.
  28.   // We set Position property of the form to poDesigned because we
  29.   // need the form's position before showing it.
  30.   Left := (Screen.DesktopWidth - Width) div 2;
  31.   Top := (Screen.DesktopHeight - Height) div 2;
  32.   // We create a bitmap object for storing the screen behind the form.
  33.   Background := TBitmap.Create;
  34.   Background.Width := Width;
  35.   Background.Height := Height;
  36.   // We get device context of the screen and copy the screen behind the form
  37.   // to the created bitmap.
  38.   DC := GetDC(0);
  39.   try
  40.     BitBlt(Background.Canvas.Handle, 0, 0, Width, Height, DC, Left, Top, SRCCOPY);
  41.   finally
  42.     ReleaseDC(0, DC);
  43.   end;
  44.   // We set Backgrund property of PicShow to captured screen image. By this trick,
  45.   // the form will seem as transparent.
  46.   PicShow.BgPicture.Assign(Background);
  47.   // To reduce chance of flickering (only when PicShow is used as non-windowed
  48.   // control we may sometime have flickers) we set background color of the form
  49.   // to color of upper left pixel of the captured screen.
  50.   Color := Background.Canvas.Pixels[0,0];
  51.   // We don't need the bitmap object, then we free it.
  52.   Background.Free;
  53.   // Finally we select a transition effect as random.
  54.   Randomize;
  55.   PicShow.Style := Random(High(TShowStyle))+1;
  56. end;
  57.  
  58. class function TSplashForm.Execute: TSplashForm;
  59. begin
  60.   Result := TSplashForm.Create(nil);
  61.   with Result do
  62.   begin
  63.     // Makes PicShow seem as transparent.
  64.     Initialize;
  65.     // Displays the splash form.
  66.     Show;
  67.     // To prevent flickering, updates the form immediately.
  68.     Update;
  69.     // Starts image transition. For splash forms don't use PicShow as Threaded.
  70.     // When threaded is true, transition will start after activation of main form.
  71.     PicShow.Execute;
  72.     // Waits one second before continuing the rest of application. If your
  73.     // applications creates lot of forms you don't need to wait here, the splash
  74.     // will remain on the screen until creating the last form of the application.
  75.     Sleep(1000);
  76.   end;
  77. end;
  78.  
  79. end.
  80.