Splash screen with text on it that uses its own thread

Download Source Code and Example


Purpose:

Shows a splash screen with extra features:
  • Enables dynamic writing of text on the splash-screen
  • Enables dynamic displaying bitmaps transparently on the splash-screen
  • All text-effects (text, sizes, fonts, positions) can be changed within a timer-procedure This allows you to create "animated" splash-screens
  • Uses a second thread, useful especially for long startup-time of application

How to use:

1. You have to create the spash within your CMainFrame::OnCreate().
Then, set bitmap, text and some other settings (text-positions and how long the splash should appear) and call CreateThread().
That's all. The thread is destroyed and deleted automatically!
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	CSplashThread *pThread = new CSplashThread();
	pThread->AddStringHeaderMain("My Application");
	// .. some other settings
	pThread->SetTimerDuration(5000); // 5 seconds
	pThread->CreateThread();


	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	// ...
}
2. If you want extra features, create your own thread-class derived from CSplashThread (as done in the sample, download-size is 140 kB). Within this sample, the internal timer is activated. Each timer resets the position of the Header-text and repaints the splash. This creaes an animated splash-screen.

How it works:

* The splash-screen uses the class CSplashThread which is derived from CWinThread. The splash-Window is created from the internal CSplashThread::InitInstance(). This function is called when the thread is created with CWinThread::CreateThread().
* In InitInstance() the Splash-Window is created. Then the splash-window redirects some important messages, like painting, timer, to the creating CSplashThread-class. This class handles these messages.
* The thread is destroyed when the "finish-timer arrives" with SetTimerDuration(). It calls HideSplashScreen() (you can call this function also directly, like in the sample). HideSplashScreen() calls DestroyWindow() of the splash-window.
* If you want extras, just derive from the class and override some functions, as shown in the example.

Remarks:

* If you have enchancements to the code, mail to mloibl@moss.de
* The sample uses the function DrawTransparentBitmap(). The original code is from Q79212 and some places also here on www.codeguru.com. It is changed, because the code doesn't work with mapping-modes other than MM_TEXT
* There should be no reason for the code not working with unicode
* This code was build with MFC shipped with VC++5.0, Enterprise Edition, Service Pack 3

Last updated: 14 May 1998



Comments

  • Example app flickers

    Posted by Legacy on 09/28/2000 12:00am

    Originally posted by: Dan Colasanti

    On my machine (NT4, 466MHz P-III), the sample app's moving graphic flickers badly...

    Reply
  • Help required!!!!!!

    Posted by Legacy on 01/27/2000 12:00am

    Originally posted by: S. R.

    I want the following functionality:
    
    

    In OnCreate() of MainFrame: A modal dialog box pops up just before 'return 0' and this dialog box accepts some input(for example, your name).
    This name is displayed on the splash screen and afterwards it is terminated.

    Does anyone know how to do this?

    Reply
  • DynamicSplashScreen: Bug?

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

    Originally posted by: Dmitry Barashev

    Something that looks like a bug was found in method 
    
    CSplashThread::DrawTransparentBitmap(). The following line:

    // Place the original bitmap back into the bitmap sent here.
    pDCTemp->BitBlt(0, 0, ptSize.x, ptSize.y - abs(ptSize.y), pDCSave, 0, 0, SRCCOPY);

    contains expression: ptSize.y - abs(ptSize.y)
    that is suspected to return zero. Thus, source bitmap becomes corrupted.
    When you try to place it one more time, you will see a wonderful
    black square.

    BarD.

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

Top White Papers and Webcasts

  • You may already know about some of the benefits of Bluemix, IBM's open platform for developing and deploying mobile and web applications. Check out this webcast that focuses on building an Android application using the MobileData service, with a walk-through of the real process and workflow used to build and link the MobileData service within your application. Join IBM's subject matter experts as they show you the way to build a base application that will jumpstart you into building your own more complex app …

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds