Adding a Splash Screen to Your Applications

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

Environment: VC6, Win32

Introduction

Seemingly, every application I create has some lengthy processing in the WM_CREATE section of code. Sometimes, this delay before my main window is displayed causes users to click again on the application icon, thus starting yet another instance of the application. This SPLASH C++ class allows me to easily display a startup splash screen or other information before the main application window is displayed.

Before developing this class, I had tried to use Dialog boxes and timers to simulate a splash screen with limited success. But that method always had less than acceptable results. This class uses a bitmap created in your resource editor and its Resource ID to define the splash screen.

This code uses the bare Win32 API. MFC is NOT REQUIRED!

Using the SPLASH Class

The first thing to do is create the splash screen bitmap. This can be done externally, and then imported into your resource editor, or created within the editor. The resource editor will assign it an ID such as IDB_BITMAP1. This bitmap can be any size. The splash screen window will size to fit it automatically.

In your C++ code, include the SPLASH.H header file; then, create a splash class instance as follows:

  #include "splash.h"
  //global variables
  SPLASH mysplash;

Of course, you'll also have to include your project SPLASH.CPP. Alternatively, you can compile SPLASH.CPP and SPLASH.H to a LIB file and include that in your project.

In your WM_CREATE section of your WndProc, initialize the splash screen with the SPLASH::Init() method as follows:

  mysplash.Init(hWnd,hInst,IDB_BIMAP1);

The Init() method takes a window handle of the parent window of the splash screen, in this case hWnd. The second parameter is the instance handle of the parent Window. Of course, the third parameter is the resource ID of the splash screen bitmap.

After initializing the splash screen, two other methods are used to show or hide the splash screen, Those methods are coincidently Hide() and Show(); both take no parameters.

To display the splash screen, you would do this:

   mysplash.Show();

To hide the splash screen, oddly enough, you would do this:

   mysplash.Hide();

One member variable, (BOOL) SHOWING, is used to programmatically determine whether the splash screen is currently displayed. This allows you to set a timer and hide the splash screen after a predetermined length of time, or hide it upon a mouse click or any other window event.

Example code for this is as follows:

        case WM_LBUTTONDOWN:
            if(mysplash.SHOWING)
                {
                 mysplash.Hide();
                }
            break;

The code below shows the SPLASH class being used in an application.

  #include "splash.h"
  //global variables
  SPLASH mysplash;
   .
   .
   .
  WndProc(...)
   .
   .
   .
        case WM_LBUTTONDOWN:
            if(mysplash.SHOWING)
                {
                 mysplash.Hide();
                }
            break;
        case WM_CREATE:
             mysplash.Init(hWnd,hInst,IDB_BITMAP1);
             mysplash.Show();
             //simulate lengthy window initialization
             Sleep(4000);
             //hide the splash screen as the main window appears
             mysplash.Hide();
            break;

I hope you find this class useful in your application development. I would appreciable feedback via e-mail or the comments section of this article.

Downloads

Download source - 2 Kb


Comments

  • WndProc

    Posted by richiebabes on 11/28/2005 01:49pm

    There is no explanation as to how to use the WndProc thingie.

    Reply
  • Very Good

    Posted by Legacy on 11/05/2003 12:00am

    Originally posted by: Paul

    Simple and elegant. Just what I was looking for. I also #included "stdafx.h" in splash.cpp, and away I went...

    Reply
  • Exactly what I needed

    Posted by Legacy on 04/24/2003 12:00am

    Originally posted by: Vladimir Chesnokov

    Thank you very much!

    To all that call this sample useless: you're so stupid, it should hurt.

    Reply
  • Useless

    Posted by Legacy on 03/05/2003 12:00am

    Originally posted by: Lax

    Hi, this is worthless. Better way is to create a window (WS_POPUP style) in an own thread, it does not affect your program loading time. Create when starting loading and end thread when application has loaded. Thats it.

    Reply
  • Just the 1000th version "Hello, World"

    Posted by Legacy on 01/27/2003 12:00am

    Originally posted by: Someguy

    Isn't it?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date