Opening splash screens?

Opening splash screens?

Can anyone suggest how to implement a nice opening splash screen for a CVF Windows application (Windows 95/98/2000/XP environment with Pentium CPU)?

publicaciones de 2 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de Jugoslav Dujic

A caveat first: don't use a splash screen if your application is ready very fast -- that can be quite annoying. OTOH splash screens (especially if accompanied with a progress bar or something similar) are nice when it's necessary to indicate to the user that your application is doing something and it's not hung.

Splash screen is usually implemented as a WS_POPUP window without WS_CAPTION and WS_BORDER styles; you could even use a modeless dialog with appropriate styles. I usually design it in CorelDRAW and then export it as a 256-color bitmap (to reduce size), then import it in Visual Studio as a resource; later do a LoadBitmap or LoadImage from the code. Displaying it in the window is a piece of cake -- just do a SelectObject(hDC, hBitmap) in WM_PAINT handler. You can also draw some changeable additional info (version number) and put some controls onto it (progress bar).

However, the caveat above poses another problem: if the data are indeed loaded & crunched for a relatively long time (as in my case -- 1 to 20 seconds), the application is really hung, so it cannot process messages and thus cannot update splash screen. To overcome this, I used the following structure:
- CreateWindow for splash screen in WinMain. ShowWindow(SW_HIDE) on all other windows (except perhaps for frame window)
- CreateThread for loading data from WinMain
- Enter message loop
- In ThreadProc, load & crunch the data. From time to time, SendMessage(PBM_STEPIT) to the progress bar located at the splash screen
- At the end of ThreadProc, hide splash screen, show other windows, enable menu & toolbar etc.

If the data loading is short, you may use a short timer (CreateTimer)(a second or so) intended for the splash screen. In SplashWindowProc, do a DestroyWindow after receiving second timer message.

HTH
Jugoslav

Jugoslav www.xeffort.com

Inicie sesión para dejar un comentario.