[英]Quickest way to implement a C++ Win32 Splash Screen
What's a simple way to implement a c++ Win32 program to...实现 C++ Win32 程序的简单方法是什么...
- display an 800x600x24 uncompressed bitmap image - 显示一个 800x600x24 的未压缩位图图像
- in a window without borders (the only thing visible is the image) - 在没有边框的窗口中(唯一可见的是图像)
- that closes after ten seconds - 十秒后关闭
- and doesn't use MFC - 并且不使用 MFC
If you're targeting modern versions of Windows (Windows 2000) and above, you can use the UpdateLayeredWindow function to display any bitmap (including one with an alpha channel, if so desired).如果您的目标是现代版本的 Windows (Windows 2000) 及更高版本,您可以使用UpdateLayeredWindow函数来显示任何位图(包括带有 alpha 通道的位图,如果需要的话)。
I blogged a four-part series on how to write a C++ Win32 app that does this.我在博客上写了一个关于如何编写 C++ Win32 应用程序来执行此操作的四部分系列文章。 If you need to wait for exactly ten seconds to close the splash screen (instead of until the main window is ready), you would need to use Dan Cristoloveanu's suggested technique of a timer that calls DestroyWindow.
如果您需要等待十秒钟来关闭启动画面(而不是直到主窗口准备好),您将需要使用 Dan Cristoloveanu 建议的调用 DestroyWindow 的计时器技术。
Register a class for the splash window and create a window using these styles:为启动窗口注册一个类并使用这些样式创建一个窗口:
_
POPUPWINDOW: will make sure your window has no caption/sysmenu _
POPUPWINDOW:将确保您的窗口没有标题/系统菜单_
EX _
TOPMOST: will keep the splash screen on top of everything. _
EX _
TOPMOST:将启动画面保持在一切之上。 Note that this is a bit intrusive. Use CreateDIBSection to load the bitmap.使用 CreateDIBSection 加载位图。 It should be easy, since BMP files are essentially dumps of DIB structures.
这应该很容易,因为 BMP 文件本质上是 DIB 结构的转储。 Or do what Ken said and use LoadImage.
或者按照 Ken 说的去做并使用 LoadImage。
Handle the WM _
PAINT or WM _
ERASEBKGND message to draw the bitmap on the window.处理 WM
_
PAINT 或 WM _
ERASEBKGND 消息以在窗口上绘制位图。
On WM _
CREATE set a timer of 10 seconds and when Windows sends the WM _
TIMER message, have the window destroy itself.在 WM
_
CREATE 上设置一个 10 秒的计时器,当 Windows 发送 WM _
TIMER 消息时,让窗口自行销毁。
The key point here is to use layered window .这里的关键是使用分层窗口。
You can start with a win32 wizard generated project and change CreateWindow call to CreateWindowEx and set WS_EX_LAYERED as extended window style and combination of WS_POPUP and WS_SYSMENU as window style.您可以从 win32 向导生成的项目开始,将 CreateWindow 调用更改为CreateWindowEx ,并将 WS_EX_LAYERED 设置为扩展窗口样式,并将 WS_POPUP 和 WS_SYSMENU 的组合设置为窗口样式。 When you do that launch your application it will be invisible.
当您这样做时,启动您的应用程序它将是不可见的。 Then you should use UpdateLayeredWindow to paint your image.
然后你应该使用UpdateLayeredWindow来绘制你的图像。 You may also need AlphaBlend function if you want use PNG image with alpha layer.
如果您想使用带有 alpha 层的 PNG 图像,您可能还需要AlphaBlend函数。
Hope this helps!希望这可以帮助!
You can:你可以:
It's a Win32 api FAQ这是一个 Win32 api 常见问题解答
See professional Win32api forum news://194.177.96.26/comp.os.ms-windows.programmer.win32 where it has been answered hundreds of times for 20 years..见专业的Win32api论坛新闻://194.177.96.26/comp.os.ms-windows.programmer.win32 20年来已回答数百次..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.