CSplash�A Splash Window Class

Introduction

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.

Features

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

Limitations

  1. Works only on WinXP/Win2000 and later
  2. Image formats other than BMP are not supported
  3. Text messages or progress bar to display initialization progress is not present, although 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 example, if your image is a red circle with some logo or text inside it in blue, fill all the region outside the circle with a color such as 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 thed ShowSplash metho to show the splash screen. The function returns immediately. You then can complete all your initialization and, at the end, call CloseSplash to remove the splash window. The code follows:

#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
splash1.ShowSplash();

// your startup initialization code goes here

// Close the splash screen
splash1.CloseSplash();

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 SplashClient.cpp source file 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 SetLayeredWindowAttributes call that is used to make the window transparent from USER32.dll into a g_pSetLayeredWindowAttributes function pointer.

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 g_pSetLayeredWindowAttributes function pointer to make the requested color transparent for the CSplash window.

The RegAndCreateWindow private function registers and creates the window for the splash window. The window procedure used with this window is an ExtWndProc external function. 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 CSplash::WindowProc member function.

CSplash::WindowProc contains code to call OnPainton receiving a 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.



About the Author

Abhinaba Basu

Abhinaba loves coding for the sheer fun of it. He started programming in 1995 with BASIC and then moved through Cobol, Pascal, Prolog, C, C++, VisualBasic and VC++. He received a Bachelor of Technology degree from University of Calcutta in 2001. Abhinaba is originally from the City of Joy, Kolkata in India, but now codes and lives in Noida close to Delhi. His hobby is coding which also happens to be his job. Besides coding he loves traveling.

Downloads

Comments

  • Why all people are extremely wrong in regards to shoes and the reason why you really should check this out ebook.

    Posted by BobHotgloff on 05/25/2013 03:48am

    Techniques of sneakers you could potentially reap the benefits of starting today. [url=http://www.shoesjp.biz/new-balance【ニューバランス】-c-670.html]ニューバランス キッズ[/url] Reasons to all sorts of things that you've read about shoes is almost certainly entirely wrong and what you must know. [url=http://www.shoesjp.biz/nike【ナイキ】-c-634.html]nike[/url] Simple article explains the most important details of sneakers together with everything that you want to undertake today. [url=http://www.kutujp.biz/]靴 通販[/url] New shoes Guide Unveil A Way To Rule The sneakers Scene [url=http://www.kutujp.biz/アディダス-adidas-c-4.html]アディダス シューズ[/url] The reasons almost everything you found out about shoes is truly completely wrong and what you need to learn. [url=http://www.kutujp.biz/アシックス-asics-c-3.html]アシックス すくすく[/url] The total magic formula for sneakers that you're able to understand about now. [url=http://www.kutujp.biz/ナイキ-nike-c-13.html]ナイキ[/url] Brand new posting discloses the intel on shoes and therefore reasons why you have got to take action right away. [url=http://www.kutujapan.org/]ベルーナ[/url] All new sneakers Guide Explains Method To Dominate The shoes Market [url=http://www.kutujapan.org/adidas-アディダス-c-74.html]adidas originals[/url] All new shoes Book Exposes Strategy To Dominate The shoes Marketplace [url=http://www.kutujapan.org/new-balance-ニューバランス-c-13.html]ニューバランス[/url] What the researchers usually aren't revealing about sneakers and in what ways this can affect you. [url=http://www.kutujapan.org/nike-ナイキ-c-78.html]nike[/url] Reasons to people are dead wrong on shoes and also the reason why you ought to see this analysis.

    Reply
  • Flicker

    Posted by robhead on 08/19/2005 02:23am

    Hi Abhinaba Basu,
    
       I ran across your code while searching for various methods people have used to create a splash screen in VC++. Your article and code were very interesting; however, I noticed that when I ran the demo, there was a brief flicker when the splash screen first appeared. Adding the following case statement to handle the WM_ERASEBKGND message appeared to fix the problem for me, so I thought I would share my changes with you.
    
    Thanks,
    
    Rob
    
    LRESULT CALLBACK CSplash::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        //  We need to handle on the WM_PAINT message
        switch(uMsg)
        {
            HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
                
        // Stop flicker when splash screen appears
        case WM_ERASEBKGND:
           // stop the default processing of this message
           // by returning 1
           return (LRESULT)1; // say we handled it
        }
    
        return DefWindowProc (hwnd, uMsg, wParam, lParam) ;
    }

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

Top White Papers and Webcasts

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Businesses are moving more and more of their customer transactions to the web. Security is understandably a top concern as online transactions increase, so it is important to make sure your electronic signature provider meets the highest security standards. That means more than simply passing a security audit or obtaining a certification. This white paper provides recommendations for taking a broader view of e-signature security, and answers key questions that help identify the security requirements against …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds