Toll Free: (877) 723-1442 U.S. and Canada
Support
ActiveX / COM
Visual C++ / MFC
Customer Spotlight
Corporate Partners
Contact Sales

Call center available M-F 9:00 - 6:00 US Eastern Time.

U.S. and Canada
(877) 723-1442

International
(517) 625-5729

Email

Dialog With Splash Screen

Author: Kirk Stowell
Posted: November 16, 2004
Environment: Visual C++ MFC

Downloads:
  article04_prj.zip - Source Files with Demo Project [249 KB]
  article04_src.zip - Source Files Only [2.71 KB]

If you have ever created a dialog application, and then tried to add a splash screen using the splash screen component, you may have found out that it won't allow you to.  This article is a quick tip for adding a splash to your dialog application using the CSplashWnd class.  This class is an enhanced version of the one that is normally generated by the splash component for a document view project.

In order to use the CSplashWnd in our dialog based application, we will have to override three functions, CDialog::OnInitDialog(), CWinApp::InitInstance() and CWinApp::PreTranslateMessage(MSG* pMsg).  OnInitDialog and InitInstance should have already been added to your project when you created it if you used the AppWizard, however you may have to add PreTranslateMessage to your CWinApp derived class.

Step 1:

Add the following line of code to your CDialog::OnInitDialog() method just before it loses scope.  The first argument to ShowSplashScreen is the time out value in milliseconds.  This is how long the splash screen will be displayed before it closes.  The second argument is the resource identifier of the bitmap image that we will be using as the splash screen. The last argument is the parent window.  This parameter can be NULL.

 // Create and show the splash screen.

 CSplashWnd::ShowSplashScreen(3000, IDB_SPLASH24, this);

 

 return TRUE;  // return TRUE  unless you set the focus to

               // a control

 }

Step 2:

Add the following line of code, toward the very beginning of the CWinApp::InitInstance(), just after the call ParseCommandLine(...).  You will need to add ParseCommandLine if it is not already included.

 BOOL CDialogsplApp::InitInstance()

 {

     // Enable the splash screen component based on the command

     // line info.

 

     CCommandLineInfo cmdInfo;

     ParseCommandLine(cmdInfo);

 

     CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);

Step 3:

Use Class Wizard to override CWinApp::PreTranslateMessage(MSG* pMsg), and add the following lines of code:

 BOOL CDialogsplApp::PreTranslateMessage(MSG* pMsg)

 {

     // Route messages to the splash screen while it is visible

     if (CSplashWnd::PreTranslateAppMessage(pMsg)) {

         return TRUE;

     }

 

     return CWinApp::PreTranslateMessage(pMsg);

 }



Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Other products and/or company names may be trademarks or registered trademarks of their respective owners.