Click here to Skip to main content
13,353,322 members (51,227 online)
Click here to Skip to main content
Add your own
alternative version


73 bookmarked
Posted 6 Jul 2004

CSplash - A Splash Window Class

, 6 Jul 2004
Rate this:
Please Sign up or sign in to vote.
This article describes creation of splash windows using Win32 APIs


A very common requirement for applications that take a lot of time to start, is to throw up a nice looking splash window at startup. Here I will discuss how such splash windows can be developed using the new layering APIs available with Win2000 and later versions of Windows.

The splash screen supports the following features

  1. Transparency
  2. Bitmap files for the splash image
  3. Simple non-MFC, C++ interface
  4. Uses only Win32 calls


  1. Works only on WinXP/Win2000 and later
  2. Image formats other than bmp is not supported
  3. Text messages or progress bar to display initialization progress is not present though it can be added if required

This application also shows how visually rich modules can be developed using C++ and Win32 without MFC.

Preparing the Image

First create the image you would like to show as the splash in your favorite image editor. Then choose the part of the image you would not like to be rendered on the screen and give it a particular color that does not occur anywhere else on the image. For an example if your image is a red circle with some logo or text inside it in blue then fill all the region outside the circle with a color like green (anything other than red and blue, I used grey 128,128,128). Note the R, G, B values of the color.

Using CSplash

The interface of the class is very simple. Use the overloaded constructor and specify the bitmap file path and the color on it to be made transparent. Then use the method ShowSplash to show the splash screen. The function returns immediately. You can then complete all your initialization and at the end, call CloseSplash to remove the splash window. Following is the code

#include "splash.h"

// Include the class header in your file
// Give the path of the image and the transparent color
CSplash splash1(TEXT(".\\Splash.bmp"), RGB(128, 128, 128));

//  Display the splash

// your start up initialization code goes here

// Close the splash screen

The other alternative is to use the default constructor and then use individual calls to set up the bitmap path and transparent color. In the sample project the source file SplashClient.cpp contains code that demonstrates both ways of using the CSplash class.

Under the hood

The class is implemented using Win32 API calls.

The constructor stores the pointer to the layering Win32 call SetLayeredWindowAttributes that is used to make the window transparent from USER32.dll into a function pointer g_pSetLayeredWindowAttributes.

The SetBitmap method opens the bitmap file, loads it and stores a handle to it in the m_hBitmap member. It also stores its width and height in m_dwWidth and m_dwHeight.

SetTransparentColor calls MakeTransparent which sets the layering style of the window and uses the function pointer g_pSetLayeredWindowAttributes to make the requested color transparent for the CSplash window.

The private function RegAndCreateWindow registers and creates the window for the splash window. The window procedure used with this window is an external function ExtWndProc. With the CreateWindowEx call we pass the this pointer. This makes the pointer to CSplash class reach the ExtWndProc function as lparam with the WM_CREATE message. ExtWndProc stores this pointer and forwards all subsequent messages to the member function CSplash::WindowProc

CSplash::WindowProc contains code to call OnPaint on receiving WM_PAINT message. Inside OnPaint we select the bitmap (in m_hBitmap) to a device context in memory and then BitBlt it to the screen device context. And we are done displaying the splash window.

To close the window CloseSplash destroys the window and unregisters the class associated with the window.


  • Date Posted: July 02, 2004


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
I just love coding. I started programming in 1995 with BASIC and then moved through Cobol, Pascal, Prolog, C, C++, VB, VC++ and now C#/.NET.

I received a Bachelor of Technology degree in Computer Science from University of Calcutta in 2001.

I worked for some time in Texas Instruments, Adobe Systems and now in Microsoft India Development Center in the Visual Studio Team Systems.

I am from the City of Joy, Kolkata in India, but now live and code Hyderabad.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Psy0116-Jul-12 16:26
memberPsy0116-Jul-12 16:26 
QuestionGreat article Pin
sameera wijerathne20-Jun-12 0:02
membersameera wijerathne20-Jun-12 0:02 
GeneralFull Screen Video and Splash Screen Problem Pin
ScotDolan1-Oct-09 11:17
memberScotDolan1-Oct-09 11:17 
GeneralMy vote of 2 Pin
g.s.virdi3-Jul-09 8:38
memberg.s.virdi3-Jul-09 8:38 
Questiondelay showing main dialog until all initialization have done? Pin
beyond57765-Apr-07 19:48
memberbeyond57765-Apr-07 19:48 
QuestionAnyone use this for VS 8? Pin
b-lo the8-Sep-06 11:04
memberb-lo the8-Sep-06 11:04 
GeneralRedrawing splash screen with changing text Pin
steve coward29-May-06 15:26
membersteve coward29-May-06 15:26 
Generalsome questions. Pin
babyspidy6-Oct-05 20:22
memberbabyspidy6-Oct-05 20:22 
GeneralRe: some questions. Pin
abhinaba6-Oct-05 23:42
memberabhinaba6-Oct-05 23:42 
GeneralRe: some questions. Pin
babyspidy7-Oct-05 6:58
memberbabyspidy7-Oct-05 6:58 
GeneralRe: some questions. Pin
abhinaba7-Oct-05 21:43
memberabhinaba7-Oct-05 21:43 
GeneralRe: some questions. Pin
babyspidy8-Oct-05 8:44
memberbabyspidy8-Oct-05 8:44 
GeneralOutput of Text Pin
x-robi9-May-05 11:45
memberx-robi9-May-05 11:45 
Generalwho can solve this problem... Pin
Anonymous11-Aug-04 4:56
sussAnonymous11-Aug-04 4:56 
QuestionConstruct from bitmap resource? Pin
Ravi Bhavnani7-Jul-04 10:43
memberRavi Bhavnani7-Jul-04 10:43 
AnswerRe: Construct from bitmap resource? Pin
abhinaba7-Jul-04 20:29
memberabhinaba7-Jul-04 20:29 
GeneralRe: Construct from bitmap resource? [modified] Pin
Soliant15-Jun-06 3:43
memberSoliant15-Jun-06 3:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 7 Jul 2004
Article Copyright 2004 by abhinaba
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid