主线程忙时在Delphi中显示启动画面 [英] Displaying splash screen in Delphi when main thread is busy

查看:173
本文介绍了主线程忙时在Delphi中显示启动画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在应用程序加载时显示启动画面。然而,一些第三方组件在启动期间阻塞主线程几秒钟,这会导致所有表单不更新。是否可以使用自己的线程启动屏幕,以便主线程忙时更新?

I'd like to display splash screen while the application is loading. However some 3rd party components block main thread during initilization for several seconds, which causes all forms not to update. Is it possible to have splash screen with own thread so it would update also when main thread is busy?

应用程序是win32和Delphi版本2007。

The application is win32 and Delphi version 2007.

编辑:我试图避免未抽出的闪屏效果,如果某些其他窗口(来自其他应用程序)位于启动屏幕的顶部,则会发生这种情况,例如,将其替换为另一个应用程序和返回。

I'm trying to avoid "undrawn splash screen" effect, which happens if some other windows (from other applications) are on the top of splash screen, eg alt-tabbing to another application and back.

推荐答案

您可以在另一个线程中运行启动屏幕,但是您将需要使用原始的Windows API调用或实现VCL类的第三方库(如键对象库)。然而,不要从飞行线程访问VCL的东西。

You can run the splash screen in another thread, but then you will need to use raw Windows API calls or a third-party library (like Key Objects Library) that implements VCL-like classes. Do however not access VCL stuff from splash thread.

如果你去那条路线(我不认为你应该,因为这是很多工作,没有什么收获),请务必从多线程中观察有关Windows API访问的规则。 Google为例如用户界面线程获取更多信息。

If you go that route (which I don't think you should, as it is a lot of work for little gain), be sure to observe the rules about Windows API access from multiple threads. Google for example for "user interface threads" for more information.

编辑

我以前没有意识到,但实际上实际上有一个组件实现了一个 Delphi的Threaded Splashscreen 在CodeCentral上。使用这个组件可能(没有尝试过)实际上很容易将闪屏显示在不同的线程中,但是从副线程访问VCL的警告仍然存在。

I wasn't aware of it before, but there is actually a component implementing a Threaded Splashscreen for Delphi on CodeCentral. Using this component it may (haven't tried it) actually be easy to have the splash screen in a different thread, but the warning against VCL access from secondary threads remains.

这篇关于主线程忙时在Delphi中显示启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆