Click here to Skip to main content
11,583,555 members (63,855 online)
Click here to Skip to main content

CSplashScreenEx : a non rectangular splash screen class with Alpha blending

, 1 Oct 2002 278.5K 10.5K 192
Rate this:
Please Sign up or sign in to vote.
CSplashScreenEx allows to display a non rectangular bitmap with informations about the init of your app

Sample Image - SplashScreenEx.jpg

Introduction

A little time ago I was looking for a Splash Screen class which would allow me to display a non rectangular bitmap without masking the background. Since I didn't find a class that matched with my needs, I developed my own Splash Screen class :- CSplashScreenEx

Compatibility

This class needs MFC to be either statically or dynamically linked in your project; it has been written, compiled and tested under Visual Studio .NET (but should work well with VC6)

How to use the Class

The class is very easy to use: Just add SplashScreenEx.h and SplashScreenEx.cpp into your project, then include SplashScreenEx.h into your application. To display the splash screen just include these lines in your OnInitDialog() function:

CSplashScreenEx *pSplash=new CSplashScreenEx();
pSplash->Create(this,NULL,2000,CSS_FADE | CSS_CENTERSCREEN | CSS_SHADOW);
pSplash->SetBitmap(IDB_SPLASH,255,0,255);
pSplash->Show();

And that's it, the splash screen appears for 2000 ms and then disappears and frees the memory allocated.

Important note - The class must be allocated on the heap since it is automatically destroyed when it disappears.

CSplashScreenEx *pSplash=new CSplashScreenEx()

The splash screen can also be used to display the loading progression of your app, as seen in the Sample number 2:

CSplashScreenEx *pSplash=new CSplashScreenEx();
pSplash->Create(this,"CSplashScreenEx dynamic text:",0,CSS_FADE | 
                        CSS_CENTERSCREEN | CSS_SHADOW);
pSplash->SetBitmap(IDB_SPLASH,255,0,255);
pSplash->SetTextFont("Impact",100,CSS_TEXT_NORMAL);
pSplash->SetTextRect(CRect(125,60,291,104));
pSplash->SetTextColor(RGB(255,255,255));
pSplash->SetTextFormat(DT_SINGLELINE | DT_CENTER | DT_VCENTER);
pSplash->Show();

Sleep(1000);
pSplash->SetText("You can display infos");

Sleep(1000);
pSplash->SetText("While your app is loading");

Sleep(1000);
pSplash->SetText("Just call Hide() when loading");
	
Sleep(1000);
pSplash->SetText("is finished");
Sleep(1500);

pSplash->Hide();

Class Documentation

CSplashScreenEx::Create

BOOL Create(CWnd *pWndParent,LPCTSTR szText=NULL,DWORD dwTimeout=2000,DWORD dwStyle=CSS_FADE | CSS_CENTERSCREEN | CSS_SHADOW);

Create the Splash Screen which stays hidden until Show() is called

Arguments

  • pWndParent: The parent window (this)
  • szText: The text displayed in your splash screen
  • dwTimeout: The time in milliseconds before the splash screen disappears. if 0 the splash screen stays forever Smile | :)
  • dwStyle: Can be a combination of the following values:
    • CSS_FADEIN : Fade In animation while appearing
    • CSS_FADEOOUT: Fade Out animation while disappearing
    • CSS_FADE=CSS_FADEIN | CSS_FADEOUT : Fade in + Fade out
    • CSS_SHADOW : Displays a shadow under the splash screen
    • CSS_CENTERSCREEN : The splash screen is centered on the screen
    • CSS_CENTERAPP: The splash screen is centered on the parent window
    • CSS_HIDEONCLICK: The splash screen disappears and is destroyed when a key is pressed or it is clicked with the mouse

CSplashScreenEx::SetBitmap

BOOL SetBitmap(UINT nBitmapID,short red=-1,short green=-1,short blue=-1);

BOOL SetBitmap(LPCTSTR szFileName,short red=-1,short green=-1,short blue=-1);

Associate the splash screen with a bitmap

Arguments

  • nBitmapId: Resource ID for the bitmap
  • szFileName: Path for the bitmap on the hard drive
  • red,green,blue: Transparency color for the bitmap (RGB color). Set these to -1 to disable bitmap transparency

CSplashScreenEx::Show

void Show();

Show the splash screen

CSplashScreenEx::Hide

void Hide();

Hide and destroy the splash screen

CSplashScreenEx::SetText

void SetText(LPCTSTR szText);

Change the text displayed in the splash screen

CSplashScreenEx::SetTextFont

void SetTextFont(LPCTSTR szFont,int nSize,int nStyle);

Change the Font of the text

Arguments

nStyle can be one or a combination of the following values:

  • CSS_TEXT_NORMAL
  • CSS_TEXT_BOLD
  • CSS_TEXT_ITALIC
  • CSS_TEXT_UNDERLINE

CSplashScreenEx::SetTextDefaultFont

void SetTextDefaultFont();

Set the system default font for the text displayed in the splash screen

CSplashScreenEx::SetTextColor

void SetTextColor(COLORREF crTextColor);

Change the text color

CSplashScreenEx::SetTextRect

void SetTextRect(CRect& rcText);

Change the text rect boundaries

CSplashScreenEx::SetTextFormat

void SetTextFormat(UINT uTextFormat);

Change the text format; see the DrawText function in the MSDN for the different values (default is DT_CENTER | DT_VCENTER | DT_WORDBREAK)

Technical issues

When SetBitmap() is called, if a transparency color has been specified, a GDI region is generated (thanks to Davide Pizzolato code) and this region is applied to the splash screen window (SetWindowRgn(...)). Thanks to this, the window is not anymore rectangular. The rest of the code is basic stuff, in the WM_PAINT handler, the background bitmap is blit on the window. Please refer to the code for more details about the implementation.

Conclusion

I hope this class will be useful to you, if you find any memory or GDI leaks or if you have suggestions to enhance this class, please post a comment. If you use this class in a freeware, shareware or commercial app, please let me know, I'll be happy Smile | :)

License

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

Share

About the Author

John O'Byrne
Web Developer
United States United States
I live in Santa Clara CA and work as a software engineer for SAP Business Objects.

My areas of expertise are user interface developments in Eclipse RCP / SWT / Draw 2D and C#

You may also be interested in...

Comments and Discussions

 
QuestionLicense Pin
eric benhamou14-May-13 5:14
membereric benhamou14-May-13 5:14 
GeneralI got the transparency working on Aero Pin
Gernot Frisch11-Jan-11 7:16
memberGernot Frisch11-Jan-11 7:16 
GeneralRe: I got the transparency working on Aero Pin
tianshiwokao26-Oct-11 21:11
membertianshiwokao26-Oct-11 21:11 
QuestionVS2008 Unicode MDI gives assert Pin
Divya Rathore25-Aug-08 16:34
memberDivya Rathore25-Aug-08 16:34 
Questionhow to show splash screen during loading dlls? Pin
yph2004010727-Nov-07 15:04
memberyph2004010727-Nov-07 15:04 
QuestionProbably a bug? Pin
min_2_max16-Aug-07 16:01
membermin_2_max16-Aug-07 16:01 
General(Small ?) Problem on Windows Vista [modified] Pin
Fran-No8-Aug-07 5:39
memberFran-No8-Aug-07 5:39 
GeneralRe: (Small ?) Problem on Windows Vista Pin
Fran-No10-Aug-07 0:30
memberFran-No10-Aug-07 0:30 
GeneralRe: (Small ?) Problem on Windows Vista Pin
Fran-No30-Aug-07 2:25
memberFran-No30-Aug-07 2:25 
GeneralRe: (Small ?) Problem on Windows Vista Pin
kelvin_gl13-Jan-08 21:10
memberkelvin_gl13-Jan-08 21:10 
GeneralRe: (Small ?) Problem on Windows Vista Pin
Fran-No14-Jan-08 0:20
memberFran-No14-Jan-08 0:20 
GeneralPixel format Generic Implementation only Pin
mitesh velani20-Sep-06 16:11
membermitesh velani20-Sep-06 16:11 
QuestionSetWindowPos() in Show() causes problem Pin
bitkidoku21-Dec-05 5:09
memberbitkidoku21-Dec-05 5:09 
GeneralImprovement: Multiple Text Fields Pin
Michael Stammberger17-Nov-05 12:37
memberMichael Stammberger17-Nov-05 12:37 
GeneralRe: Improvement: Multiple Text Fields Pin
min_2_max16-Aug-07 16:16
membermin_2_max16-Aug-07 16:16 
GeneralRe: Improvement: Multiple Text Fields Pin
min_2_max16-Aug-07 16:25
membermin_2_max16-Aug-07 16:25 
GeneralRe: Improvement: Multiple Text Fields Pin
Michael Stammberger16-Aug-07 21:01
memberMichael Stammberger16-Aug-07 21:01 
GeneralGreat work Pin
jefflewis19-Sep-05 1:59
memberjefflewis19-Sep-05 1:59 
GeneralSound Pin
sicks21-Jul-05 11:22
membersicks21-Jul-05 11:22 
GeneralSome errors when using in UNICODE project Pin
bitmensch15-Jul-05 1:59
memberbitmensch15-Jul-05 1:59 
QuestionHow to use the class in SDI or MDI project? Pin
sibang jang11-Jul-05 16:30
susssibang jang11-Jul-05 16:30 
AnswerRe: How to use the class in SDI or MDI project? Pin
sibang jang11-Jul-05 17:38
susssibang jang11-Jul-05 17:38 
QuestionWhy parent window is needed? Pin
Yogurt23-Jun-05 9:47
memberYogurt23-Jun-05 9:47 
AnswerRe: Why parent window is needed? Pin
kelvin_gl14-Jul-05 17:18
memberkelvin_gl14-Jul-05 17:18 
AnswerRe: Why parent window is needed? Pin
Brad Bruce28-Jan-06 10:35
memberBrad Bruce28-Jan-06 10:35 
GeneralWindows 2000 SP4 Pin
Johnnyfartpants30-May-05 20:28
memberJohnnyfartpants30-May-05 20:28 
GeneralRe: Windows 2000 SP4 Pin
Johnnyfartpants28-Jul-05 1:44
memberJohnnyfartpants28-Jul-05 1:44 
GeneralA better CreateRgnFromBitmap function Pin
kintz1-Mar-05 0:34
memberkintz1-Mar-05 0:34 
GeneralRe: A better CreateRgnFromBitmap function Pin
Bigsteve871-Sep-10 5:49
memberBigsteve871-Sep-10 5:49 
GeneralUse of CSS_SHADOW appears to hang system Pin
Walter Blume27-Jan-05 7:57
memberWalter Blume27-Jan-05 7:57 
GeneralRe: Use of CSS_SHADOW appears to hang system Pin
varandas794-Feb-08 6:58
membervarandas794-Feb-08 6:58 
QuestionHow to show Splash Screen till user clicks.. Pin
Jigar Mehta14-Nov-04 17:46
memberJigar Mehta14-Nov-04 17:46 
AnswerRe: How to show Splash Screen till user clicks.. Pin
Jigar Mehta14-Nov-04 23:29
memberJigar Mehta14-Nov-04 23:29 
GeneralRe: How to show Splash Screen till user clicks.. Pin
Jazee22-Nov-04 11:18
memberJazee22-Nov-04 11:18 
GeneralRe: How to show Splash Screen till user clicks.. Pin
Jigar Mehta22-Nov-04 16:50
memberJigar Mehta22-Nov-04 16:50 
QuestionHow to use the class in SDI or MDI project? Pin
Jack_Cai16-Jul-04 0:51
memberJack_Cai16-Jul-04 0:51 
AnswerRe: How to use the class in SDI or MDI project? Pin
Stiewie31-Jul-04 6:21
memberStiewie31-Jul-04 6:21 
GeneralRe: How to use the class in SDI or MDI project? Pin
Jack_Cai1-Aug-04 19:11
memberJack_Cai1-Aug-04 19:11 
GeneralRe: How to use the class in SDI or MDI project? Pin
Andrew Allen19-May-05 14:04
memberAndrew Allen19-May-05 14:04 
Generalreally nice but ... Pin
Stiewie14-May-04 10:01
memberStiewie14-May-04 10:01 
Generalthe main frame window is inactive Pin
Helen Liu28-Apr-04 22:38
memberHelen Liu28-Apr-04 22:38 
GeneralStrange behaviour in WinNT Pin
vjplusplus27-Feb-04 0:04
membervjplusplus27-Feb-04 0:04 
GeneralMy mistake Pin
vjplusplus29-Feb-04 20:59
membervjplusplus29-Feb-04 20:59 
GeneralAny O/S other than 2000/XP Pin
Kevin Gutteridge3-Feb-04 9:57
memberKevin Gutteridge3-Feb-04 9:57 
GeneralRe: Any O/S other than 2000/XP Pin
Kevin Gutteridge3-Feb-04 11:25
memberKevin Gutteridge3-Feb-04 11:25 
GeneralRe: Any O/S other than 2000/XP Pin
Kevin Gutteridge3-Feb-04 12:40
memberKevin Gutteridge3-Feb-04 12:40 
GeneralRe: Any O/S other than 2000/XP Pin
John O'Byrne3-Feb-04 23:06
memberJohn O'Byrne3-Feb-04 23:06 
GeneralRe: Any O/S other than 2000/XP Pin
Kevin Gutteridge4-Feb-04 2:34
memberKevin Gutteridge4-Feb-04 2:34 
GeneralRe: Any O/S other than 2000/XP Pin
John O'Byrne4-Feb-04 3:54
memberJohn O'Byrne4-Feb-04 3:54 
GeneralRe: Any O/S other than 2000/XP Pin
Kevin Gutteridge4-Feb-04 6:47
memberKevin Gutteridge4-Feb-04 6:47 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150603.1 | Last Updated 2 Oct 2002
Article Copyright 2002 by John O'Byrne
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid