Splash screens with wxSplashScreen
posted on: 2010-08-01 10:34:37
This isn't going to be the biggest tutorial as I have had very little time this week. So this one is going to be very simple. I am going to show you how to make a simple splash screen for your wxWidget's application. It is something very easy to implement, and will give an application that professional feel.
Splash screens are very useful for developers when there is a time gap between the user running the application and when the application becomes responsive to the user.
This is usually because of the time needed to populate objects, read in files, connecting to servers, etc...
In which time the impatient user may decide to click on your application multiple times or complain saying that your application is slow.
By implementing a splash screen (the wxSplashScreen class) while this initialization is taking place, lets your user know that the program is starting.
It can also give your application a professional and finished feel (if your splash image isn't as ridiculous as mine).
You should choose something more professional to display... below is purely for comedy purposes.
You must make sure that you include the wx/splash.h header in order to have access to the wxSplashScreen class. I have set my splash screen to display for 3 seconds. I also sleep for 3 seconds to give the impression that something important is happening, where in reality you would have some initialization code.
bool MainApp::OnInit()
{
wxBitmap splashBitmap;
splashBitmap.LoadFile(wxT("splash.bmp"), wxBITMAP_TYPE_BMP);
wxSplashScreen* splash = new wxSplashScreen(splashBitmap,
wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 3000,
NULL, -1, wxDefaultPosition, wxDefaultSize,
wxSIMPLE_BORDER|wxSTAY_ON_TOP);
wxYield();
//I sleep for 3 seconds here while the splash screen is
//being displayed. In reality you will need to the time to do some
//initialization.
sleep(3);
SetTopWindow( new MainDialog( NULL ) );
GetTopWindow()->Show();
return true;
}
After this time the application then starts.
I appologise for the comedy in this weeks post, I am in one of those comedy moods.



