This is Part II of a series on creating a splash screen application in native
code. For more information, see the
Introduction and the
Code License.
Part II: Displaying the Window
In Part I I showed how to
create a HBITMAP with the splash screen image. This installment will show how
to create a window that displays that image.
Each Win32 window needs a window class, and the splash screen window is no
different. The window class for the splash screen window will be fairly
standard, although the interesting thing is that we can use DefWindowProc as
the WndProc because we don’t actually need special processing for any window
messages. The window class also specifies an icon because I prefer to have
splash screens show up in the Alt+Tab list, and it looks better if we provide
an icon. (Note that in this code, error handling has been omitted.)
When creating the windows, I use an old trick (a hidden owner window) to make
the splash screen appear in the Alt+Tab list, but not in the taskbar. If you
wanted the splash screen to also appear in the taskbar, you could drop the
hidden owner window. If you didn’t want it to appear in the Alt+Tab list or
the taskbar, you could use the WS_EX_TOOLWINDOW extended window style (and
omit the owner window).
The window now exists, but isn’t sized or positioned correctly, and has no
content. The UpdateLayeredWindow function can be used to correct all these
problems at once. There are several steps to this process:
Calculate the location of the splash screen (in order to centre it on the primary monitor)
Create a memory DC that contains the splash image
Specify a blend function that will use the per-pixel alpha of the splash image
Pass all this information to UpdateLayeredWindow
The beauty of layered windows and the UpdateLayeredWindow function is that the
splash window doesn’t have to respond to WM_PAINT messages; Windows will paint
it (and blend it correctly with the windows below it) by default.
Now that the splash screen is being displayed, we need to launch the actual
application (and then dismiss the splash screen); the next installments will
cover this.