unit WelcomeFrm;

interface

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

type
  TWelcomeForm = class(TForm)
    imgWelcome: TImage;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

function ShowWelcome: THandle;

procedure HideWelcome;


implementation

{$R *.dfm}

var
  WelcomeForm: TWelcomeForm;
const
  // 渐变最大时间（毫秒）
  MaxShowAnimateTime = 1500;
  MaxHideAnimateTime = 700;

function ShowWelcome: THandle;
var
  I: Integer;
  iFirstTime: Cardinal;
begin
  WelcomeForm := TWelcomeForm.Create(nil);
  if FileExists(GetAppFilePath + 'Welcome.jpg') then
    WelcomeForm.imgWelcome.Picture.LoadFromFile(GetAppFilePath + 'Welcome.jpg');
  Result := WelcomeForm.Handle;
  WelcomeForm.Show;
  iFirstTime := GetTickCount;
  for I := 0 to 255 do
  begin
    if I mod 5 = 0 then
    begin
      WelcomeForm.AlphaBlendValue := I;
      WelcomeForm.Update;
      if GetTickCount - iFirstTime > MaxShowAnimateTime then
        Break;
    end;
  end;

  WelcomeForm.AlphaBlendValue := 255;
  Sleep(2000);
  SetForegroundWindow(WelcomeForm.Handle);
end;

procedure HideWelcome;
var
  I: Integer;
  iFirstTime: Cardinal;
begin
  if WelcomeForm = nil then
    Exit;
  iFirstTime := GetTickCount;
  for I := 255 downto 0 do
  begin
    if I mod 10 = 0 then
    begin
      WelcomeForm.AlphaBlendValue := I;
      WelcomeForm.Update;
      if GetTickCount - iFirstTime > MaxHideAnimateTime then
        Break; 
    end;
  end;
  WelcomeForm.AlphaBlendValue := 0;
  WelcomeForm.Free;
  WelcomeForm := nil;
end;

end.
