News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: How can I show a splash screen during my application startup?

By Daniel Strigl, March 12, 2004.
Print version

Question

I want to show a splash screen during my application startup that hides automatically after a given time or when the user taps with the stylus pen on the screen. How it can be done?

Answer

The easiest way is to create a simple window without boarder and caption that draws the splash image in the OnPaint message. After the window creation start a timer for the time you want to show the splash screen. When the timer run off or the user taps with the stylus pen on the screen destroy the splash screen window.

Splash screen

I have written a simple class, called CSplashWnd, that includes all the necessary stuff for the window creation and the timer setup, so that the usage is very simple.

First add the following two files (included in the sample application at the end of this article) to your project:

  • SplashWnd.h
  • SplashWnd.cpp

After that add the following code to your application files:

In the application main class, XxxApp.h and XxxApp.cpp:

... // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CSplashApp) public: virtual BOOL InitInstance(); virtual BOOL PreTranslateMessage(MSG* pMsg); //}}AFX_VIRTUAL ... ... #include "SplashWnd.h" ... BOOL CSplashApp::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class // Forward message to splash window if (CSplashWnd::PreTranslateAppMessage(pMsg)) return TRUE; return CWinApp::PreTranslateMessage(pMsg); }

In the frame window class, MainFrm.cpp:

... int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; // Add the buttons and adornments to the CommandBar. if (!InsertButtons(tbButtons, nNumButtons, IDR_MAINFRAME, nNumImages) || !AddAdornments(dwAdornmentFlags)) { TRACE0("Failed to add toolbar buttons\n"); return -1; } // Show the splash window CSplashWnd::ShowSplashScreen(IDB_SPLASH, 5000, this); return 0; } ...

The function call CSplashWnd::ShowSplashScreen(IDB_SPLASH, 5000, this); will show the image IDB_SPLASH for 5 seconds in the center of the screen.

Sample application

You can download a working sample application here.

Related resources:

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House