Dialog with Splash Screen Example Code

Download Example Project - (142 kb)

Follow these steps to add a splash screen to your dialog based application:

  • Copy the Splash.cpp and Splash.h files from this example project to your project.
  • Add the following code to your applications InitInstance() method in the CWinApp derived class:
  • #include "Splash.h"
    BOOL CDialogsplApp::InitInstance()
      // CG: The following block was added by the Splash Screen component.
         CCommandLineInfo cmdInfo;
  • Next, use class wizard to add the OnCreate method to the CDialog derived class .cpp file, and add the following code to it:
  • #include "Splash.h"
    int CDialogsplDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
       if (CDialog::OnCreate(lpCreateStruct) == -1)
          return -1;
       // CG: The following line was added by the Splash Screen component.
       return 0;

Last updated: 29 March 1998


  • Added code to specify bmp file.

    Posted by kluzra on 06/18/2004 04:45pm

    I like the splasher code.  Works great.  I added the following code to use a file or resource item.  Code checks for filename in the home directory of the app, specified in string constant IDS_SPLASH_FILE, i.e. splash.bmp.  If it doesn't exist, then it will default to the resource, IDB_SPLASH.
    	BOOL Create(CWnd* pParentWnd = NULL);
    	void HideSplashScreen();
    	static BOOL c_bShowSplashWnd;
    	static CSplashWnd* c_pSplashWnd;
    //New code
    	BOOL LoadBitmap();
    	CPalette  m_Palette;
    	int       m_nHeight;
    	int       m_nWidth;
    #include NameApp.h
    BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
    //	if (!m_bitmap.LoadBitmap(IDB_SPLASH))
    //		return FALSE;
            // Call LoadBitmap to load file or resource
    BOOL CSplashWnd::LoadBitmap()
    	CString mBmpName;
    	//Tell the splash screen which bitmap to use, 
    	CString mBitMap = ((CNameApp *)AfxGetApp())->GetHomeDirectory() + mBmpName;
    	CFileFind	mFind ;
      //Use LoadImage to get the image loaded into a DIBSection
      HBITMAP hBitmap;
      if (mFind.FindFile(mBitMap) )
      //Check that we could load it up  
      if (hBitmap == NULL)       
        return FALSE;
      //Get the color depth of the DIBSection
      BITMAP bm;
      GetObject(hBitmap, sizeof(BITMAP), &bm);
      m_nHeight = bm.bmHeight;
      m_nWidth = bm.bmWidth;
      //Covert from the SDK bitmap handle to the MFC equivalent
      //If the DIBSection is 256 color or less, it has a color table
      if ((bm.bmBitsPixel * bm.bmPlanes) <= 8 )     
        //Create a memory DC and select the DIBSection into it
        CDC memDC;
        CBitmap* pOldBitmap = memDC.SelectObject(&m_bitmap);
        //Get the DIBSection's color table
        RGBQUAD rgb[256];
        ::GetDIBColorTable(memDC.m_hDC, 0, 256, rgb);
        //Create a palette from the color table
        LPLOGPALETTE pLogPal = (LPLOGPALETTE) new BYTE[sizeof(LOGPALETTE) + (256*sizeof(PALETTEENTRY))];
        pLogPal->palVersion = 0x300;       
        pLogPal->palNumEntries = 256;
        for (WORD i=0; i<256; i++)       
          pLogPal->palPalEntry[i].peRed = rgb[i].rgbRed;
          pLogPal->palPalEntry[i].peGreen = rgb[i].rgbGreen;
          pLogPal->palPalEntry[i].peBlue = rgb[i].rgbBlue;
          pLogPal->palPalEntry[i].peFlags = 0;
        //Clean up
        delete pLogPal;
      else  //It has no color table, so use a halftone palette     
        CDC* pRefDC = GetDC();
      return TRUE;   
    	CString GetHomeDirectory();
    CString CNameApp::GetHomeDirectory()
      TCHAR sFilename[_MAX_PATH];
      TCHAR sDrive[_MAX_DRIVE];
      TCHAR sDir[_MAX_DIR];
      TCHAR sFname[_MAX_FNAME];
      TCHAR sExt[_MAX_EXT];
      GetModuleFileName(AfxGetInstanceHandle(), sFilename, _MAX_PATH);
      _tsplitpath(sFilename, sDrive, sDir, sFname, sExt);
      CString rVal(CString(sDrive) + CString(sDir));
      int nLen = rVal.GetLength();
      if (rVal.GetAt(nLen-1) != _T('\\'))
        rVal += _T("\\");
      return rVal;

  • Display Splash Longer.

    Posted by Legacy on 11/13/2003 12:00am

    Originally posted by: Bulldog XTRM

    I'm new to programming.

    I'm trying to make a simple text based program and have included a splash screen with photo. Currently the program works as intended, but the splash screen is extremely fast. How can I add a delay so that the splash screen is displayed for a longer time? I'm using MS Visual Basic 6.0.

    • SetTimer

      Posted by kluzra on 06/18/2004 04:13pm

      In the SetTimer line, SetTimer(1, 750, NULL); change the 750 to a higher number. Russ

  • how to show the .gif type pictures

    Posted by Legacy on 07/03/2001 12:00am

    Originally posted by: wangsh

    i find the background picture used in the splashscreen is .bmp type picture,i want to show a moving picture such as .gif type picture,how do?

  • How to add delay for displaying the main window

    Posted by Legacy on 03/25/1999 12:00am

    Originally posted by: V

    How can I add a delay so that the main window isn't shown until the splash screen is gone?

    I tried to hide the main window, and show it when the HideSplashScreen function is called, but I always get a very short flash of the outline of the main window before it gets hidden.

    Otherwise, it looks like it's working fine.

    Any ideas?


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

Top White Papers and Webcasts

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date