简体   繁体   English

创建动画的splashscreen delphi 7

[英]Create animated splashscreen delphi 7

I'm trying to make an animated splashscreen while my app loads his database. 当我的应用加载他的数据库时,我正在尝试制作动画的闪屏。 I already created a splashscreen but I want to make the image "move" from left to right while the db is getting converted. 我已经创建了一个启动画面,但我希望在转换数据库时使图像从左向右“移动”。 Been searching for a while now but all I could find is about progress bars... 一直在寻找一段时间,但我能找到的只是进度条......

Here's my code: 这是我的代码:

SplashScreen := TSplashScreen.Create(Application) ;
SplashScreen.Show;
Application.Initialize;
SplashScreen.Update;
SplashScreen.lblStatus.Caption:='Loading...';
SplashScreen.Update;
SplashScreen.lblStatus.Caption:='Updating database...';
SplashScreen.Update;
Application.Initialize;
Application.CreateForm(TfmMain, fmMain);
Sleep(1000);

Application.CreateForm(TfmPrefs, fmPrefs);
Application.CreateForm(TfmCode, fmCode);
Application.CreateForm(TfmEmps, fmEmps);
Application.CreateForm(TfmRest, fmRest);
Application.ShowMainForm:=FALSE;

SplashScreen.Hide;
SplashScreen.Free;
Application.Run;

On my splashscrren form, I created 5 duplicates of the same image and while the Main Form is created, I want the image to be Visible and not visible in alternance... ex: 在我的splashscrren表单上,我创建了5个相同图像的副本,并且在创建主表单时,我希望图像是可见的,而不是交替显示... ex:

while my db loads... begin
Splashscreen.Image1.Visible:=FALSE;
SplashScreen.Update;
Sleep(25);
SplashScreen.Image1.Visible:=FALSE;
SplashScreen.Update;
SplashScreen.Image2.Visible:=TRUE;....

and so on! 等等!

Any thoughts? 有什么想法吗?

Doing heavy work in the main thread during startup (like initializing database and many forms) does not work well with splash screens. 在启动期间在主线程中执行繁重的工作(如初始化数据库和许多表单)对于启动屏幕不起作用。 The main thread is too occupied to do anything with the GUI. 主线程太忙了,无法对GUI做任何事情。 Putting Sleep into the code will not work, since this will stop the main thread to do any work at all. 将Sleep放入代码中将不起作用,因为这将阻止主线程完成任何工作。

This leaves you with two options : 这有两个选择:

  1. Do your database initializations in another thread. 在另一个线程中进行数据库初始化。 Sometimes also only initializing the main form is a good option. 有时也只是初始化主窗体是一个不错的选择。 The database thread can send progress messages to the splash form via PostMessage calls. 数据库线程可以通过PostMessage调用将进度消息发送到splash表单。

  2. Start the splash screen in a separate thread. 在单独的线程中启动启动屏幕。 This is kind of tricky, because you may not use the VCL from another thread. 这有点棘手,因为你可能不会使用另一个线程的VCL。 And also you must avoid blocking the message queue. 此外,您必须避免阻止消息队列。 Luckily, Peter Below has made a good example how to do a threaded splash screen using only windows api calls. 幸运的是,Peter Below已经很好地展示了如何仅使用windows api调用来执行线程启动画面

There are some more information in this SO thread : displaying-splash-screen-in-delphi-when-main-thread-is-busy . 这个SO线程中还有一些信息: display-splash-screen-in-delphi-when-main-thread-is-busy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM