zoukankan      html  css  js  c++  java
  • delphi之完美Splash方案

    前言:网上有很多介绍delphi创建闪屏的代码,大多只是在程序开启前显示一个闪屏,但是却没有说如何在闪屏上显示程序加载的进度,于是笔者有意思介绍一下这种闪屏方式。

    1.创建一个窗体(TfrmSplash),放入一个TImageBox,加载一幅图片,调整好TImageBox与图片的大小,然后在其上放入一个TLabel,name=LblStatus,用于显示加载进度文字。然后将TfrmSplash设置为不自动创建。

    2.加入如下代码(代码很简单,就不用解释太多)

    1. unit UntFormSplash;  
    2.   
    3. interface  
    4.   
    5. uses  
    6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
    7.   Dialogs, ExtCtrls, StdCtrls;  
    8.   
    9. type  
    10.   TfrmSplash = class(TForm)  
    11.     Image1: TImage;  
    12.     LblStatus: TLabel;  
    13.   private  
    14.     { Private declarations }  
    15.     FParam:Pointer;  
    16.   public  
    17.     { Public declarations }  
    18.     class function Execute(AParam:Pointer):Boolean;  
    19.     procedure SetStatusText(Value: string);  
    20.   published  
    21.     property StatusText : string write SetStatusText;  
    22.   end;  
    23.   
    24. var  
    25.   SplashForm: TfrmSplash;  
    26.   
    27. implementation  
    28.   
    29. {$R *.dfm}  
    30.   
    31. { TfrmSplash }  
    32.   
    33. class function TfrmSplash.Execute(AParam:Pointer): Boolean;  
    34. begin  
    35.   with TfrmSplash.Create(nil) do  
    36.   try  
    37.     FParam := AParam;  
    38.     Result := ShowModal = mrOk;  
    39.   finally  
    40.     Free;  
    41.   end;  
    42. end;  
    43.   
    44. procedure TfrmSplash.SetStatusText(Value: string);  
    45. begin  
    46.   LblStatus.Caption := Value;  
    47.   Update;  //这句非常重要,不加的话,界面会阻塞,文字也就不会更新显示  
    48.   Sleep(1000); //这句根据自己实际情况来调整,主要是怕闪屏太快关闭,达不到效果  
    49. end;  
    50.   
    51.   
    52. end.  

    3. 在项目的.dpr文件中加入如下代码:

    Delphi代码  
    1. begin  
    2.   
    3.   Application.Initialize;  
    4.   
    5.   SplashForm := TfrmSplash.Create(Application);  
    6.   SplashForm.Show;  
    7.   SplashForm.Update;  
    8.   
    9.   SplashForm.StatusText := '准备启动...';  
    10.   SplashForm.Update;  
    11.     
    12.   Application.CreateForm(TDM, DM);  
    13.   Application.CreateForm(TfrmMain, frmMain);  
    14.     
    15.   SplashForm.Hide;  
    16.   SplashForm.Free;  
    17.   
    18.   Application.Run;  
    19. end.  

    4.这一步就是主窗体加载数据的时候,边加载边更新闪屏的进度文字了:

    Delphi代码  
    1. procedure TfrmMain.FormCreate(Sender: TObject);  
    2. begin  
    3.   
    4.   with SplashForm do  
    5.   try  
    6.     StatusText := ('开始初始化内存...');  
    7.     FCacheHash := TStringHashMap.Create(CaseInsensitiveTraits, 255);  
    8.     FCurrentClients := TList.Create;  
    9.     //VST.NodeDataSize := SizeOf(TTagCustomListItem);  
    10.     //VST.RootNodeCount := 2;  
    11.     VST.NodeDataSize := SizeOf(TMyTreeNodeDate);  
    12.     StatusText :=('初始化内存完成');  
    13.   
    14.     StatusText :=('开始加载客户端列表...');  
    15.     BuildGroupTree;  
    16.     StatusText :=('加载客户端列表完成');  
    17.   
    18.     StatusText :=('开始加载分组信息...');  
    19.     AddELVDefaultGroup;  
    20.     StatusText :=('开始初始化内存');  
    21.   
    22.     StatusText :=('开始初始化数据...');  
    23.     G_DefNetImpl := TDefNetImpl.Create();  
    24.     G_DefNetImpl.RegisterObserver(Self);  
    25.     StatusText :=('全部数据加载完毕,程序即将启动...');  
    26.   
    27.   finally  
    28.   
    29.   end;  
    30.   
    31.   
    32. end;  

    收功,试着运行一下吧,一个漂亮的splash诞生了.

  • 相关阅读:
    codeforces 455B A Lot of Games(博弈,字典树)
    HDU 4825 Xor Sum(二进制的字典树,数组模拟)
    hdu 1800 Flying to the Mars(简单模拟,string,字符串)
    codeforces 425A Sereja and Swaps(模拟,vector,枚举区间)
    codeforces 425B Sereja and Table(状态压缩,也可以数组模拟)
    HDU 4148 Length of S(n)(字符串)
    codeforces 439D Devu and Partitioning of the Array(有深度的模拟)
    浅谈sass
    京东楼层案例思维逻辑分析
    浅谈localStorage和sessionStorage
  • 原文地址:https://www.cnblogs.com/plug/p/4557173.html
Copyright © 2011-2022 走看看