Click here to Skip to main content
12,501,708 members (61,683 online)
Click here to Skip to main content
Add your own
alternative version

Stats

36.9K views
635 downloads
29 bookmarked
Posted

Easy Splash in Five Minutes

, 27 Aug 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
An easy way to create a splash for your MFC program in less than five minutes
Sample Image - EasySplash.jpg

Introduction

Have you ever wanted a quick and easy way to add a splash screen to your MFC programs?

I'm going to show you how to add a Splash to your program in less than five minutes.
All you need is a bitmap picture you want to use as your Splash.

This article is designed for Visual Studio 2005, but will probably work in earlier versions.

  • Open your projects resource view.
  • Expand the tree, right click on the rc file and choose add resource.
  • From the pop up, choose bitmap and press the import button.
  • Browse to the location of the BMP you want to use as your splash and click open.
    Expand the bitmap leaf in the resource view and change the id TO IDB_SPLASH.
  • Now right click on the Dialog leaf and choose "Insert Dialog".
  • Expand the dialog leaf and if the new dialog is not already open in the resource editor, double click the new IDD_DIALOG1 to open the new dialog.
  • Delete the OK and Cancel button.
  • Change the following properties for the dialog:
    • ID to IDD_SPLASH
    • Border to thin
    • Title bar to false
    • Topmost to true
    • Center to true

  • See the thin blue line? Drag it with the mouse until it is even with the sides of the dialog.
  • From the toolbox, drag a picture control into the dialog and place it in the upper left corner.
  • Depending on the size of the picture you want for your splash, resize the dialog to be larger than the picture you want to use. You may need to resize the thin blue line again.
    Select the picture control.
  • Change the picture control ID to IDC_SPLASH and the type to Bitmap.
    You will notice that now that the type is bitmap the image property is no longer grayed out.
  • Change the image property with the dropdown to IDB_SPLASH.

  • Resize the dialog so that the picture just fits.
  • Right click on the dialog and choose "Add Class".
  • Set the class name to CDialogSplash and hit finish.
  • In the class view, select CDialogSplash and press the "messages" button in the properties area and scroll down to WM_TIMER.
  • Use the drop down to add an OnTimer function to the CDialogSplash class.
  • Replace the code in the OnTimer function with CDialog::OnOK();
  • In the class view, select CDialogSplash and press the "overrides" button and scroll down to OnInitDialog.
  • Use the drop down to add an OnInitDialog function. Update the code as follows:
BOOL CDialogSplash::OnInitDialog()
{
    CDialog::OnInitDialog();
    CRect rectPic, rectWin;
    GetWindowRect(&rectWin);
    m_pic.GetWindowRect(&rectPic);
    MoveWindow(rectWin.left, rectWin.top,rectPic.Width(),rectPic.Height());

    return TRUE; 
}

Ok now let's use the splash we created.

Since most people would like their splash to display before the main program finishes loading, we are going to place our splash call near the top of the InitInstance function in the Application class.

In the class view, click on your application class. For this example, we will use the demo project I created and select CEasySplashApp.

Right click CEasySplashApp and choose Add Variable. Change the access to protected, the type to CDialogSplash and the name to m_splash.

In the class view Double click on the InitInstance function in the CEasySplashApp class and add the following code to the top of the function right after the CWinApp::InitInstance();

m_splash.Create(IDD_SPLASH, this->m_pMainWnd); 
m_splash.ShowWindow(SW_SHOW);
m_splash.SetTimer(1,2000, NULL);

You should have something like this now:

Compile your project and run it. You should see your splash display when your program starts and close after the timer runs out.

In the demo project, I added a button to show the splash again so you don't have to keep restarting the program just to see the splash again.

I hope you found this article useful.

History

  • 26th August, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

kencocomputers
Software Developer (Senior)
United States United States
I am a contract developer of windows based software written in C++.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralMessage! Pin
cristitomi19-Mar-07 5:26
membercristitomi19-Mar-07 5:26 
GeneralWell Written Pin
lallous4-Sep-06 21:44
memberlallous4-Sep-06 21:44 
QuestionWhat is new/what is better? Pin
VictorN28-Aug-06 22:03
memberVictorN28-Aug-06 22:03 
GeneralTwo problems Pin
Todd Smith28-Aug-06 5:15
memberTodd Smith28-Aug-06 5:15 
GeneralNow, that's... Pin
Rage27-Aug-06 21:19
memberRage27-Aug-06 21:19 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160919.1 | Last Updated 27 Aug 2006
Article Copyright 2006 by kencocomputers
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid