Thema: Delphi Animierte Splash Form

Einzelnen Beitrag anzeigen

Alois

Registriert seit: 23. Jul 2005
71 Beitrдge
 
Delphi 10 Seattle Professional
 
#14

Re: Animierte Splash Form

  Alt 12. Jun 2009, 18:23
Zitat von Super_Chemiker:
Vielleicht eine blцde Frage, aber wie integriere ich so einen Splashscreen jetzt in ein Delphi Projekt? Ich wьsste nicht, wie ich das mit dem Dateityp als Formular festlege

mfG
Schau dir doch die Dateien im ASF Demo Full an.
Hier der Link: http://www.bitoff.ru/animationsplash/ASFDemoFull.zip

Gruss Alois

ASFDemoMain.pas
Delphi-Quellcode:
unit ASFDemoMain;

interface

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

type
  Tfrm_Main = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Label2Click(Sender: TObject);
    procedure Label3Click(Sender: TObject);
    procedure LabelMouseEnter(Sender: TObject);
    procedure LabelMouseLeave(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frm_Main: Tfrm_Main;

{===================================================== }
// Хранит индекс текста, который надо будет менять в процессе
  ProgressTextItem: Integer;

implementation

uses
  ASFMain;

{$R *.dfm}

procedure Tfrm_Main.FormCreate(Sender: TObject);
begin
  // Установить индекс текущей иконки
  AnimationSplashForm.ProgressIconCurrentItem := 0;
  AnimationSplashForm.TextData.Items[ProgressTextItem].Text := 'Установка стилей...';
  // в мс. приблизительно
  AnimationSplashForm.LoadingSectionTime := 1000;
  // Имитация долгого безответного действия
  Sleep(1000);

  AnimationSplashForm.TextData.Items[ProgressTextItem].Text := 'Загрузка параметров...';
  AnimationSplashForm.IncCurrentSection;
  AnimationSplashForm.IncCurrentItemIcon;
  AnimationSplashForm.LoadingSectionTime := 3000;
  // Имитация долгого безответного действия
  Sleep(3100);

  AnimationSplashForm.TextData.Items[ProgressTextItem].Text := 'Инициализация COM...';
  AnimationSplashForm.IncCurrentSection;
  AnimationSplashForm.IncCurrentItemIcon;
  AnimationSplashForm.LoadingSectionTime := 1000;
  // Имитация долгого безответного действия
  Sleep(1600);

  AnimationSplashForm.TextData.Items[ProgressTextItem].Text := 'Подключение MUI...';
  AnimationSplashForm.IncCurrentSection;
  AnimationSplashForm.IncCurrentItemIcon;
  AnimationSplashForm.LoadingSectionTime := 1000;
  // Имитация долгого безответного действия
  Sleep(500);

  AnimationSplashForm.TextData.Items[ProgressTextItem].Text := 'Загрузка интерфейса...';
  AnimationSplashForm.IncCurrentSection;
  AnimationSplashForm.IncCurrentItemIcon;
  AnimationSplashForm.LoadingSectionTime := 2000;
  // Имитация долгого безответного действия
  Sleep(2000);

  AnimationSplashForm.TextData.Items[ProgressTextItem].Text := 'Запуск...';
end;

procedure Tfrm_Main.Label2Click(Sender: TObject);
begin
  Screen.Cursor := crHourGlass;
  ShellExecute(Application.Handle, nil,
      'mailto:ASF%20-%20Andy%20BitOff<asf@bitoff.ru>?subject=AnimationSplashForm',
      nil, nil, SW_SHOWNORMAL);
  Screen.Cursor := crDefault;
end;

procedure Tfrm_Main.Label3Click(Sender: TObject);
begin
  Screen.Cursor := crHourGlass;
  ShellExecute(Application.Handle, nil,
      PChar(TLabel(Sender).Hint),
      nil, nil, SW_SHOWNORMAL);
  Screen.Cursor := crDefault;
end;

procedure Tfrm_Main.LabelMouseEnter(Sender: TObject);
var
  a: Integer;
begin
  Screen.Cursor := crHandPoint;
  a := TLabel(Sender).Tag;
  TLabel(Sender).Tag := TLabel(Sender).Font.Color;
  TLabel(Sender).Font.Color := TColor(a);
end;

procedure Tfrm_Main.LabelMouseLeave(Sender: TObject);
begin
  LabelMouseEnter(Sender);
  Screen.Cursor := crDefault;
end;

end.
ASFDemoFull.dpr
Delphi-Quellcode:
program ASFDemoFull;

uses
  Forms,
  ASFDemoMain in 'ASFDemoMain.pas{frm_Main},
  SysUtils,
  GDIPAPI,
  ASFLists in '..\..\ASFLists.pas',
  ASFMain in '..\..\ASFMain.pas';

{$R *.res}

var
  Anim1: TAnimationFrames;
  SplashImagePath, s: string;
  i: Integer;

begin
  SplashImagePath := ExtractFilePath(ParamStr(0)) + 'img\';

  AnimationSplashForm := TAnimationSplashForm.CreateFrom(SplashImagePath + 'Splash.png');
  // Здесь надо учесть, что центруется сплэш именно по размерам бэкграунда
// AnimationSplashForm := TAnimationSplashForm.CreateEmptyBackGround(196, 273, 72, 72);

  // Показывать кнопку на Панели задач
  AnimationSplashForm.ShowTaskbarButton := True;
  // Заголовок онка, если ShowTaskbarButton = True
  AnimationSplashForm.SplashFormCaption := 'Загрузка...';
  // Отрисовывать окно поверх всех
  AnimationSplashForm.SplashFormTopMost := False;
  // Скорость проявления и затухания сплэша
  // зависимость от таймера, т.е. SetTimerInterval * FadeSpeed
  AnimationSplashForm.FadeSpeed := 7;
  // Установка интервала таймера
  AnimationSplashForm.SetTimerInterval(15);

// ТЕКСТ ПРОЦЕССА
  ProgressTextItem := AnimationSplashForm.TextData.AddNewItem;
  with AnimationSplashForm.TextData.Items[ProgressTextItem] do begin
    // Показывать текст
    Visible := True;
    // Показывать тень текста
    VisibleShadow := True;
    // Рект в котором отображается текст
    TextBox := MakeRect(20, 190, 145, 20);
    // цвет текста
    Color := $FFF0F0F4;
    // цвет тени
    ShadowColor := $FF6C6C39;
    // шрифт
    FontName := 'Verdana';
    FontSize := 11;
    // центровать по горизонтали
    PositionH := StringAlignmentCenter;
  end;

// ПРОГРЕСС БАР
  with AnimationSplashForm.ProgressBar^ do begin
    // Показывать прогресс бар
    BarVisible := True;
    // Показывать рамку прогресс бара
    BarBorderVisible := True;
    // размеры прогресс бара
    BarBox := MakeRect(27, 212, 130, 10);
    // цвет прогресс бара
    BarColor := $60FFFFFF;
    // цвет бордюра
    BarBorderColor := $80F0F0F0;
  end;


  // Создадим постоянный текст, например, номер версии
  i := AnimationSplashForm.TextData.AddNewItem;
  with AnimationSplashForm.TextData.Items[i] do begin
    Visible := True;
    Text := 'version: 1.0.0.0';
    TextBox := MakeRect(27, 252, 130, 10);
    FontSize := 8;
    FontStyle := FontStyleItalic;
    PositionH := StringAlignmentCenter;
  end;


// ИКОНКИ
  // Показывать иконки
  AnimationSplashForm.ProgressIconsVisible := True;
  // Скорость проявления иконок (в процентах) в зависимости от LoadingPartTime
  // 100 значит, что иконка будет проявляться всё время (LoadingPartTime),
  // 50 - проявится за половину времени
  AnimationSplashForm.IconFullPaintPercent := 100;
  // Задать анимацию появления иконок
  AnimationSplashForm.IconAnimation := iaFade;
  // Положение первой иконки - левый край
  AnimationSplashForm.IconPosLeft := 23;
  // Положение первой иконки - верхний край
  AnimationSplashForm.IconPosTop := 226;
  // Расстояние между иконками
  AnimationSplashForm.IconSpace := 2;
  // Сколько пикс.отступать от левого края пред.иконки.
  // Если это знач. = 0, то берется значение ширины пред.иконки
  AnimationSplashForm.IconStep := 25;
  // Теперь загружаем сами иконки
  AnimationSplashForm.Icons.LoadFromFile(SplashImagePath + 'Icons.dat');
{  // Первая загрузка из файлов и сохранение в один файл
  // Затем загрузка идет уже и того файла
  AnimationSplashForm.Icons.AddFromFile(SplashImagePath + 'Styles.png');    // 1
  AnimationSplashForm.Icons.AddFromFile(SplashImagePath + 'Properties.png');// 2
  AnimationSplashForm.Icons.AddFromFile(SplashImagePath + 'Com.png');      // 3
  AnimationSplashForm.Icons.AddFromFile(SplashImagePath + 'Mui.png');      // 4
  AnimationSplashForm.Icons.AddFromFile(SplashImagePath + 'Interface.png'); // 5
  AnimationSplashForm.Icons.SaveToFile(SplashImagePath + 'Icons.dat');}



// АНИМАЦИЯ
  // Подготовим анимацию
  AnimationSplashForm.AnimationsAddFromFile(SplashImagePath + 'Animation.dat');
{  // Первая загрузка из файлов и сохранение в один файл
  // Затем загрузка идет уже и того файла
  Anim1 := TAnimationFrames.Create;
  try
    Anim1.DelayBetweenImages := 3;
    // Пауза между повторами циклов анимации
    Anim1.DelayBetweenPassage := 0;
    Anim1.PositionLeft := 42;
    Anim1.PositionTop := 79;
    for I := 0 to 17 do begin
      s := IntToStr(i);
      if Length(s) = 1 then
        s := '0' + s;
      Anim1.AddFromFile(SplashImagePath + 'Animation ' + s + '.png');
    end;
    AnimationSplashForm.AnimationsAdd(Anim1);
    Anim1.SaveToFile(SplashImagePath + 'Animation.dat');
  finally
    Anim1.Free;
  end;}


  // Устанавливает количество частей для загрузки
  // Также автоматом ProgressBarCurrentPart ставится равной 1
  AnimationSplashForm.ProgressBarSectionsCount := 5;

  // Запустить Splash
  AnimationSplashForm.StartSplash;

  Application.Initialize;
  Application.CreateForm(Tfrm_Main, frm_Main);
  // Закрыть и уничтожить
  AnimationSplashForm.CloseSplash(30, True);

  Application.Run;
end.
  Mit Zitat antworten Zitat