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

  • Thanks to the Internet of Things (IoT), physical assets are turning into participants in real-time global digital markets. The countless types of assets around us will become as easily indexed, searched and traded as any online commodity. While some industries will be tougher to transform than others – those with physical limitations, such as manufacturing, will be harder to digitize – untold economic opportunities exist for growth and advancement. Our research shows this will create a new "Economy …

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

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