Click here to Skip to main content
6,594,932 members and growing! (15,616 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Win32/64 SDK & OS » General     Intermediate License: The Common Development and Distribution License (CDDL)

Own-thread Win32 splash screen

By Kirill V. Lyadvinsky

Implementation of an own-thread splash screen, with a progress indicator using Win32 and GDI+.
VC8.0Win2K, WinXP, Win2003VS2005, Dev
Posted:8 Sep 2006
Updated:20 Jun 2008
Views:38,182
Bookmarked:70 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
20 votes for this article.
Popularity: 5.49 Rating: 4.22 out of 5

1
2 votes, 10.0%
2
2 votes, 10.0%
3
3 votes, 15.0%
4
13 votes, 65.0%
5

Sample screenshot

Introduction

Using MFC-based classes -- even with your own threads -- may lead to hang-up of the splash screen repainting while loading the application. This is because MFC has synchronization on the message queue level. So, the application stops responding to the user. CSplashWnd is a class that makes it easy to use splash screens that can always paint themselves. It is implemented using the Win32 API, but you can use it in MFC applications, as well.

How to Use the Class

The CSplashWnd uses GDI+ to show images. It allows you to use a variety of image types including BMP, GIF, JPEG, PNG, TIFF and EMF. However, you have to initialize the GDI+ library:

// Before using CSplashWnd

GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

...

// Somewhere in the end of your program

GdiplusShutdown(gdiplusToken);

The use of CSplashWnd is very simple. Just add SplashWnd.cpp and SplashWnd.h into your project and then include SplashWnd.h in your program. To initialize the splash screen, use CSplashWnd::SetImage. This method sets the image you want to see while loading the application. It can look like this:

...

CSplashWnd splash;
splash.SetImage(pImage);
splash.Show();

// ... Some long operation


splash.Hide();

...

The splash screen can have a button on the taskbar. It is created only if CSplashWnd::SetWindowName is invoked before CSplashWnd::Show. A button on the taskbar may be useful if the splash screen appears before any window is created. In that case, the user can easily find the application. You can indicate the loading progress using the CSplashWnd::SetProgress method. The first call of CSplashWnd::SetProgress leads to creating a progress control at the bottom of the splash window. It also sets the progress control to the initial state. All subsequent calls just update the progress state.

You could show more details of loading or computing process by passing text description of progress stage to CSplashWnd::SetProgress method using text string or string resource ID as additional input parameter.

...

splash.Show()
splash.SetProgress(0, L"Loading...");

for (int i =0; i < 100; ++i)
{
  // compute something

  // ...

  splash.SetProgress(i);
}

splash.SetProgress(100, L"Done.");

...

If the length of the loading operation is known, you'll want to use the CSplashWnd::SetAutoProgress method. It automatically updates the progress state using its own timer. At the moment, it updates the state one step per second. The previous code will now look like:

...

splash.Show()
splash.SetAutoProgress(0, 100, 100);

for (int i =0; i < 100; ++i)
{
  // compute something

  // here we know that one loop takes one second

}

...

History

  • August 9, 2006 - The class was written.
  • May 25, 2007 - Some synchronization has been added and the timer message ID has been fixed.
  • June 20, 2008 - New features: multimonitor support, text progress status, support for external resource handles.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)

About the Author

Kirill V. Lyadvinsky


Member
C++ Developer. In 2002 developed the first automatic eBay bidder (Last Minute Bidder) for Paragon Software GmbH.
Now - Head of R&D laboratory in ElVEES R&D center of Microelectronics.

Occupation: Team Leader
Location: Russian Federation Russian Federation

Other popular Win32/64 SDK & OS articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
QuestionAnimated Gif Support PinmemberT.Haberkern9:32 30 Jun '07  
AnswerRe: Animated Gif Support PinmemberMihai Moga15:28 20 Jun '08  
GeneralCompile example with Studio2003 PinmemberBen_AH0:36 5 Jun '07  
GeneralI can't see the progress bar in the sample project PinmemberAlexZherdev13:18 24 May '07  
GeneralRe: I can't see the progress bar in the sample project [modified] PinmemberKirill V. Lyadvinsky21:38 24 May '07  
GeneralAbitlity to run exe on a separated thread Pinmemberjohn Pure8:47 27 Sep '06  
GeneralRe: Abitlity to run exe on a separated thread Pinmemberjia3ep22:37 28 Sep '06  
GeneralBackground of my application PinmemberAlexEvans14:06 19 Sep '06  
GeneralRe: Background of my application Pinmemberjia3ep22:17 19 Sep '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 20 Jun 2008
Editor: Sean Ewington
Copyright 2006 by Kirill V. Lyadvinsky
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project